I'm sorry about this but I though you'd expect this as the types aren't 
compliant(what you may have noticed with an IDE).
I'll correct the code below:

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

using namespace CryptoPP;
using namespace std;

void EncryptAES(string& In,const string& Key,string* Out)// out is assumed 
to be empty
{
   ECB_Mode<AES>::Encryption Encryptor(Key.c_str(),Key.size());
   while(In.size() % AES::Encryption::BLOCKSIZE != 0) // resize Out to be a 
multiple of the blocksize
    In.append('\0',1);
   
   SecByteBlock OutBuffer(In.size()); 
   Encryptor.ProcessData(In.c_str(),OutBuffer,In.size()); // please verify 
directions in original code
   Out->append(OutBuffer,OutBuffer.size());
}

void DecryptAES(string& In,const string& Key,string* Out) // out is assumed 
to be empty
{
   ECB_Mode<AES>::Decryption Decryptor(Key.c_str(),Key.size());
   while(In.size() % AES::Encryption::BLOCKSIZE != 0) // resize Out to be a 
multiple of the blocksize    
    In.append('\0',1); 
   SecByteBlock OutBuffer(In.size()); 
   Decryptor.ProcessData(In.c_str(),OutBuffer,In.size()); // please verify 
directions in original code
   Out->append(OutBuffer,OutBuffer.size());
}

BR

JPM

Am Dienstag, 24. Februar 2015 02:13:30 UTC+1 schrieb Fil Nick:
>
>
>
> On Tuesday, 24 February 2015 02:56:26 UTC+10:30, Jean-Pierre Münch wrote:
>>
>> 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?
>>>
>>
>
> N:\code\Aes\aes3>cl aes.cpp
> Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x64
> Copyright (C) Microsoft Corporation.  All rights reserved.
>
> aes.cpp
> F:\VISUALCPP\VC\INCLUDE\xlocale(336) : warning C4530: C++ exception 
> handler used
> , but unwind semantics are not enabled. Specify /EHsc
> aes.cpp(10) : error C2664: 
> 'CryptoPP::CipherModeFinalTemplate_CipherHolder<CIPHE
> R,BASE>::CipherModeFinalTemplate_CipherHolder(const 
> CryptoPP::CipherModeFinalTem
> plate_CipherHolder<CIPHER,BASE> &)' : cannot convert parameter 1 from 'const 
> std
> ::string' to 'const 
> CryptoPP::CipherModeFinalTemplate_CipherHolder<CIPHER,BASE>
> &'
>         with
>         [
>             CIPHER=CryptoPP::Rijndael::Encryption,
>             BASE=CryptoPP::ECB_OneWay
>         ]
>         Reason: cannot convert from 'const std::string' to 'const 
> CryptoPP::Ciph
> erModeFinalTemplate_CipherHolder<CIPHER,BASE>'
>         with
>         [
>             CIPHER=CryptoPP::Rijndael::Encryption,
>             BASE=CryptoPP::ECB_OneWay
>         ]
>         No user-defined-conversion operator available that can perform 
> this conv
> ersion, or the operator cannot be called
> aes.cpp(12) : error C2664: 'CryptoPP::ECB_OneWay::ProcessData' : cannot 
> convert
> parameter 1 from 'std::string' to 'byte *'
>         No user-defined-conversion operator available that can perform 
> this conv
> ersion, or the operator cannot be called
> aes.cpp(17) : error C2664: 
> 'CryptoPP::CipherModeFinalTemplate_CipherHolder<CIPHE
> R,BASE>::CipherModeFinalTemplate_CipherHolder(const 
> CryptoPP::CipherModeFinalTem
> plate_CipherHolder<CIPHER,BASE> &)' : cannot convert parameter 1 from 'const 
> std
> ::string' to 'const 
> CryptoPP::CipherModeFinalTemplate_CipherHolder<CIPHER,BASE>
> &'
>         with
>         [
>             CIPHER=CryptoPP::Rijndael::Decryption,
>             BASE=CryptoPP::ECB_OneWay
>         ]
>         Reason: cannot convert from 'const std::string' to 'const 
> CryptoPP::Ciph
> erModeFinalTemplate_CipherHolder<CIPHER,BASE>'
>         with
>         [
>             CIPHER=CryptoPP::Rijndael::Decryption,
>             BASE=CryptoPP::ECB_OneWay
>         ]
>         No user-defined-conversion operator available that can perform 
> this conv
> ersion, or the operator cannot be called
> aes.cpp(19) : error C2664: 'CryptoPP::ECB_OneWay::ProcessData' : cannot 
> convert
> parameter 1 from 'std::string' to 'byte *'
>         No user-defined-conversion operator available that can perform 
> this conv
> ersion, or the operator cannot be called
>
> N:\code\Aes\aes3>
>
>  
>  
>

-- 
-- 
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