Home » Developing U++ » UppHub » Encrypted storage with streaming (OpenSSL, AES)
Encrypted storage with streaming (OpenSSL, AES) [message #23087] |
Wed, 16 September 2009 22:17 |
Mindtraveller
Messages: 917 Registered: August 2007 Location: Russia, Moscow rgn.
|
Experienced Contributor |
|
|
Sometimes we may have task to store some large file (4+ GB) or small string inside encrypted storage. I tried to make a pair classes which make it easy. This is the first version, so any ideas are welcome.
This package assumes you have OpenSSL library successfully installed and its paths are added to TheIDE.
OK, let me introduce a pair of classes called AESEncoderStream and AESDecoderStream. They support streamed adding and encryption/decryption of data. Encryption is made with AES (Rijndael) with 128, 192 or 256 bit keys.
Encrypted data 32 bytes larger than source length aligned to 16-byte boundary. I.e. if your source data is 170 bytes long, the resulting length is:
170 rounded by 16-byte pieces = 176
plus
32 (header data)
= 176 + 32 = 208 bytes.
Not so ugly for a number of applications especially if source data is large.
Here is a simple self-explanating demo:
#include <Core/Core.h>
#include <openssl/aes.h>
#include <AESStream/AESStream.h>
using namespace Upp;
CONSOLE_APP_MAIN
{
AESInit();
// Generate cryptographically stable key
String key(AESRandomString(32));
// Encryption
String sIn,sOut;
sIn = "qwertyuiop[p\tasdfghjkl;zxcvbnm,./quwiueqiwueoiquweioquweioquweiqwueicuwinuqiweqiwue pqiueci eiqniuriryuweyruweyruewrycuwbrurbywuyrwquiercbbcrebrquwey";
AESEncoderStream aesEncoder(sIn.GetLength(), key);
aesEncoder << sIn.Left(10);
aesEncoder << sIn.Mid(10,10);
aesEncoder << sIn.Right(sIn.GetLength() - 20);
sOut << aesEncoder; //do streamed encoding
// Decryption
//key.Set(0, 'a'); //uncomment to see what happens with wrong key
AESDecoderStream aesDecoder(key);
aesDecoder << sOut.Left(15); //you may add by parts
aesDecoder << sOut.Right(sOut.GetLength() - 15);
try
{
String sDecoded;
sDecoded << aesDecoder; //throw exception if key is wrong
Cout() << (sDecoded == sIn) << "\n\n"; //check if all converted successfully
}
catch (const char *xp)
{
Cout() << "\n!!Error: " << ToSystemCharset(xp);
}
}
[Updated on: Fri, 18 September 2009 11:16] Report message to a moderator
|
|
|
|
|
Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Thu, 17 September 2009 09:34
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: Weras on Thu, 17 September 2009 19:57
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Thu, 17 September 2009 22:55
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: tojocky on Fri, 18 September 2009 12:28
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Fri, 18 September 2009 13:23
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Fri, 18 September 2009 23:01
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: kasome on Wed, 23 September 2009 03:29
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Sat, 20 February 2010 17:08
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Sun, 21 February 2010 08:07
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Sun, 21 February 2010 10:38
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Sun, 21 February 2010 15:40
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Sun, 21 February 2010 16:01
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Sun, 21 February 2010 19:25
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Mon, 22 February 2010 07:54
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Mon, 22 February 2010 08:50
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Mon, 22 February 2010 11:55
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Mon, 22 February 2010 12:46
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: tojocky on Mon, 22 February 2010 15:19
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Mon, 22 February 2010 16:46
|
|
|
Building with MSC9
By: kohait00 on Wed, 03 March 2010 23:17
|
|
|
Re: Building with MSC9
By: koldo on Sat, 06 March 2010 01:49
|
|
|
Re: Building with MSC9
By: kohait00 on Sun, 07 March 2010 11:24
|
|
|
Re: Building with MSC9
By: koldo on Sun, 07 March 2010 13:47
|
|
|
Re: Building with MSC9
By: kohait00 on Sun, 07 March 2010 16:08
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Wed, 10 March 2010 17:09
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: kohait00 on Wed, 10 March 2010 20:54
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Wed, 10 March 2010 21:33
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: kohait00 on Wed, 10 March 2010 22:36
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Thu, 11 March 2010 09:12
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: kohait00 on Thu, 11 March 2010 10:29
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Thu, 11 March 2010 11:01
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: koldo on Sun, 14 March 2010 15:27
|
|
|
bazaar: DeEncrypter
By: kohait00 on Thu, 05 August 2010 21:09
|
|
|
Re: bazaar: DeEncrypter
|
|
|
Re: bazaar: DeEncrypter
By: kohait00 on Sun, 08 August 2010 11:05
|
|
|
Re: bazaar: DeEncrypter
|
|
|
Re: bazaar: DeEncrypter
By: kohait00 on Tue, 10 August 2010 15:46
|
|
|
Re: bazaar: DeEncrypter
|
|
|
Re: bazaar: DeEncrypter
By: kohait00 on Tue, 10 August 2010 21:42
|
|
|
Re: bazaar: DeEncrypter
|
|
|
Re: bazaar: DeEncrypter
By: koldo on Wed, 11 August 2010 15:29
|
|
|
Re: bazaar: DeEncrypter
|
|
|
Re: bazaar: DeEncrypter
By: koldo on Thu, 12 August 2010 13:54
|
|
|
Re: bazaar: DeEncrypter
By: kohait00 on Tue, 17 August 2010 15:58
|
|
|
Re: bazaar: DeEncrypter
By: koldo on Fri, 25 February 2011 18:52
|
|
|
Re: bazaar: DeEncrypter
|
|
|
Re: Encrypted storage with streaming (OpenSSL, AES)
By: Alboni on Fri, 23 August 2013 01:59
|
Goto Forum:
Current Time: Sat Jan 25 22:55:22 CET 2025
Total time taken to generate the page: 0.06183 seconds
|