added: to crypto:
bool Crypt(const std::string & in, std::string & out) bool Decrypt(const std::string & in, std::string & out) git-svn-id: svn://ttmath.org/publicrep/tito/trunk@396 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
ddd6ebd637
commit
a5a0201ec1
|
@ -114,6 +114,14 @@ void Crypto::Crypt(const std::wstring & in, std::wstring & out)
|
|||
}
|
||||
|
||||
|
||||
void Crypto::Crypt(const std::string & in, std::string & out)
|
||||
{
|
||||
aes.Encode((const unsigned char*)&in[0], in.size(), aes_name, uint8_tab);
|
||||
base64.Encode((const char*)&uint8_tab[0], uint8_tab.size(), out);
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
void Crypto::Crypt(const std::vector<char> & in, std::string & out)
|
||||
{
|
||||
aes.Encode((const unsigned char*)&in[0], in.size(), aes_name, uint8_tab);
|
||||
|
@ -152,6 +160,36 @@ return false;
|
|||
}
|
||||
|
||||
|
||||
bool Crypto::Decrypt(const std::string & in, std::string & out)
|
||||
{
|
||||
out.clear();
|
||||
|
||||
if( in.empty() )
|
||||
return true;
|
||||
|
||||
base64.Decode(in, aes_str);
|
||||
|
||||
if( aes.Decode((const unsigned char *)aes_str.c_str(), aes_str.size(), aes_tmp_name, uint8_tab) )
|
||||
{
|
||||
out.resize(uint8_tab.size());
|
||||
|
||||
for(size_t i=0 ; i<uint8_tab.size() ; ++i)
|
||||
out[i] = uint8_tab[i];
|
||||
|
||||
Clear();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
//log << "problem with AES decoding (skipping)" << logend;
|
||||
}
|
||||
|
||||
Clear();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool Crypto::Decrypt(const std::string & in, std::vector<char> & out)
|
||||
{
|
||||
out.clear();
|
||||
|
|
|
@ -64,6 +64,7 @@ public:
|
|||
so the 'out' string is ready to save as a normal text
|
||||
*/
|
||||
void Crypt(const std::wstring & in, std::wstring & out);
|
||||
void Crypt(const std::string & in, std::string & out);
|
||||
void Crypt(const std::vector<char> & in, std::string & out);
|
||||
|
||||
|
||||
|
@ -74,6 +75,7 @@ public:
|
|||
if 'in' is empty the 'out' will be empty too
|
||||
*/
|
||||
bool Decrypt(const std::wstring & in, std::wstring & out);
|
||||
bool Decrypt(const std::string & in, std::string & out);
|
||||
bool Decrypt(const std::string & in, std::vector<char> & out);
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue