Link to home
Start Free TrialLog in
Avatar of TheIronDuke
TheIronDuke

asked on

Rijndael string encryption in C++

I am working on a program that users can read and write AES encrypted string values. I am talking about a string that would fit in an Edit box for example. Not encryption/decryption of an entire file. I see a lot of examples of file encryption, using larger memory blocks, etc. But I am not finding anything for just individual strings.

Can anyone point me in the right direction.
Avatar of jkr
jkr
Flag of Germany image

It's actually quite straightfoward using e.g. CryptoPP (http://www.cryptopp.com/), e.g.

        std::string strEncrypted, strDecrypted; // source and target

        // ...

        CryptoPP::AutoSeededRandomPool rng;   

		RSA::PrivateKey k1;
		// load/assign key

		////////////////////////////////////////////////////////////////////////////////////

		if(!k1.Validate(rng, 3)) // validate
			throw "Rsa private key validation failed";

		////////////////////////////////////////////////
		// Decryption
		CryptoPP::RSAES_OAEP_SHA_Decryptor d(k1);

			CryptoPP::StringSource( strEncrypted, true,
				new CryptoPP::PK_DecryptorFilter( rng, d,
					new CryptoPP::StringSink(strDecrypted)
				) // PK_DecryptorFilter
			 ); // StringSource

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The below link also gives more examples for download on cryptocpp.
http://www.cryptopp.com/wiki/Advanced_Encryption_Standard