Hey Fil,

if you want to use Crypto++ there're some issues with this code, I'll come 
back to them after answering your initial question.

#include <aes.h>
#include <modes.h>
#include <string>

using namespace CryptoPP;
using namespace std;

void EncryptAES(const string& In,const string& Key,string* Out)
{
   ECB_Mode<AES>::Encryption Encryptor(Key);
   // resize Out to be a multiple of the blocksize
   Encryptor.ProcessData(*Out,In,In.size());
}

void DecryptAES(const string& In,const string& Key,string* Out)
{
   ECB_Mode<AES>::Decryption Decryptor(Key);
   // resize Out to be a multiple of the blocksize
   Decryptor.ProcessData(*Out,In,In.size());
}

This will work and encrypt you some data with AES.

However it is not secure.

   1. You may not want to encrypt each block seperately but rather combine 
   them somehow. You should consider using CTR mode if not authentication is 
   required and GCM mode if authentication is required. You'll then also need 
   an unique IV for each message.
   2. You may not want to use std::string s to hold sensitive data (such as 
   keys and plaintext), so you should consider using SecByteBlock and 
   FixedSizeSecBlock<byte,X> to transmit data. (as otherwise secret data may 
   be leaked to hard-drive or other porgrams after de-allocation)
   3. You may not wanto to call an encryption routine with a high-level 
   object. In my opinion the parameters should be (const byte* In, const byte* 
   Key, byte* Out, const byte* IV), to reach maximal portability or at least 
   use something like SecByteBlock (passed by reference)

BR

JPM

Am Montag, 23. Februar 2015 14:16:06 UTC+1 schrieb Fil Nick:
>
> How would it be possible to encrypt and decrypt strings in AES. 
> Or in short how can one replicate the functionality of the code below in 
> AES.
> http://pastebin.com/Gw0RLBNR
> I've tried to do this for a very long time.I have also done more than more 
> fair share of looking around. None of my attempts seem to work correctly 
> and they will not compiler under vs2012 or code blocks. So all I ask is 
> this does someone have an example anything?
>

-- 
-- 
You received this message because you are subscribed to the "Crypto++ Users" 
Google Group.
To unsubscribe, send an email to [email protected].
More information about Crypto++ and this group is available at 
http://www.cryptopp.com.
--- 
You received this message because you are subscribed to the Google Groups 
"Crypto++ Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to