Change AESCrypt to support mutiple key type (string and byte)
This commit is contained in:
parent
0b16b8eb9a
commit
e261782473
4 changed files with 40 additions and 3 deletions
|
@ -33,6 +33,18 @@ std::string AESCrypt::encrypt(std::string key, std::string data){
|
|||
byte digest[32];
|
||||
hash.getSHA_256(key, digest, (int)sizeof(digest));
|
||||
|
||||
return encryptRoutine(data, digest, sizeof(digest));
|
||||
|
||||
}
|
||||
//Encrypt string
|
||||
std::string AESCrypt::encrypt(byte* key, std::string data){
|
||||
|
||||
return encryptRoutine(data, key, 32);
|
||||
|
||||
}
|
||||
|
||||
|
||||
std::string AESCrypt::encryptRoutine(std::string data, byte* digest, int size){
|
||||
//Contain data encrypted
|
||||
std::string cipher;
|
||||
|
||||
|
@ -41,7 +53,7 @@ std::string AESCrypt::encrypt(std::string key, std::string data){
|
|||
try{
|
||||
//Create encoder to encrypt data
|
||||
CryptoPP::ECB_Mode<CryptoPP::AES>::Encryption encoder;
|
||||
encoder.SetKey( digest, sizeof(digest) );
|
||||
encoder.SetKey( digest, size );
|
||||
|
||||
//Encrypt data with StreamTransformationFilter with NO PADDING
|
||||
CryptoPP::StringSource ss1(data, true,
|
||||
|
@ -61,10 +73,20 @@ std::string AESCrypt::encrypt(std::string key, std::string data){
|
|||
//return encrypted data
|
||||
return cipher;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//Decrypt string
|
||||
std::string AESCrypt::decrypt(std::string key, std::string data){
|
||||
|
||||
|
|
|
@ -67,6 +67,11 @@ class AESCrypt : public AbstractSKA {
|
|||
*/
|
||||
virtual std::string decrypt(std::string key, std::string data);
|
||||
|
||||
std::string encrypt(byte* key, std::string data);
|
||||
|
||||
std::string encryptRoutine(std::string data, byte* digest, int size);
|
||||
|
||||
|
||||
private:
|
||||
HASHCrypt hash; ///< hash instance to generate SHA-256 hash code.
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue