#include <Cipher.h>
Public Member Functions | |
std::string | b64decrypt (const std::string &input) |
std::string | b64encrypt (const std::string &input) |
Cipher (const std::string &key) | |
std::string | decrypt (const unsigned char *input, size_t inputSize) |
size_t | encrypt (const std::string &input, unsigned char *&output) |
~Cipher () | |
Private Member Functions | |
size_t | bf_process_alloc (const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false) |
Private Attributes | |
BLOWFISH_CTX * | m_ctx |
cond::Cipher::Cipher | ( | const std::string & | key | ) | [explicit] |
Definition at line 9 of file Cipher.cc.
References Blowfish_Init(), gen::k, and m_ctx.
: m_ctx(new BLOWFISH_CTX){ char* k = const_cast<char*>(key.c_str()); Blowfish_Init( m_ctx, reinterpret_cast<unsigned char*>(k), key.size()); }
std::string cond::Cipher::b64decrypt | ( | const std::string & | input | ) |
Definition at line 91 of file Cipher.cc.
References base64_decode_alloc, LaserDQM_cfg::input, run_regression::ret, and cond::throwException().
Referenced by cond::CredentialStore::exportAll(), cond::CredentialStore::importForPrincipal(), cond::CredentialStore::listConnections(), cond::CredentialStore::selectForUser(), cond::CredentialStore::setPermission(), cond::CredentialStore::startSession(), cond::CredentialStore::updateConnection(), and cond::CredentialStore::updatePrincipal().
{ char* input = 0; size_t inputSize = 0; if( !base64_decode_alloc( b64in.c_str(), b64in.size(), &input, &inputSize ) ){ throwException("Input provided is not a valid base64 string.","Cipher::b64decrypt"); } std::string ret = decrypt( reinterpret_cast<const unsigned char*>(input), inputSize ); free (input); return ret; }
std::string cond::Cipher::b64encrypt | ( | const std::string & | input | ) |
Definition at line 80 of file Cipher.cc.
References base64_encode_alloc(), funct::false, dbtoconf::out, and run_regression::ret.
Referenced by cond::CredentialStore::addUser(), cond::CredentialStore::installAdmin(), cond::CredentialStore::setPermission(), cond::CredentialStore::updateConnection(), and cond::CredentialStore::updatePrincipal().
{ unsigned char* out = 0; size_t outSize = bf_process_alloc( reinterpret_cast<const unsigned char*>(input.c_str()), input.size(), out, false ); char* b64out = 0; size_t b64size = base64_encode_alloc( reinterpret_cast<const char*>(out), outSize, &b64out ); std::string ret( b64out, b64size ); free (out); free (b64out); return ret; }
size_t cond::Cipher::bf_process_alloc | ( | const unsigned char * | input, |
size_t | input_size, | ||
unsigned char *& | output, | ||
bool | decrypt = false |
||
) | [private] |
Definition at line 19 of file Cipher.cc.
References Blowfish_Decrypt(), Blowfish_Encrypt(), i, j, dttmaxenums::L, and dttmaxenums::R.
{ uInt32 L, R; unsigned int j = sizeof(uInt32); unsigned int output_size=0; for ( unsigned int i=0; i < input_size; i+=(j*2)){ output_size = i+2*j; } output = (unsigned char*) malloc( output_size ); memset(output, 0, output_size); for (unsigned int i=0; i < input_size; i+=(j*2)) { L = R = 0; unsigned int nl = 0; unsigned int nr = 0; if( input_size > i+j ){ nl = j; if( input_size > i+2*j ){ nr = j; } else { nr = input_size-i-j; } } else { nl = input_size-i; nr = 0; } if(nl) memcpy(&L, input+i, nl); if(nr) memcpy(&R, input+i+j, nr); if( !decrypt ){ Blowfish_Encrypt(m_ctx, &L, &R); } else { Blowfish_Decrypt(m_ctx, &L, &R); } memcpy(output+i, &L, j); memcpy(output+i+j, &R, j); } return output_size; }
std::string cond::Cipher::decrypt | ( | const unsigned char * | input, |
size_t | inputSize | ||
) |
Definition at line 66 of file Cipher.cc.
References dbtoconf::out, and run_regression::ret.
Referenced by cond::DecodingKey::init().
{ unsigned char* out = 0; size_t outSize = bf_process_alloc( input, inputSize, out, true ); char* sout = reinterpret_cast<char*>(out); // the output can still contain one or more \0 chars... size_t soutSize = strlen( sout ); if( soutSize < outSize ){ outSize = soutSize; } std::string ret( sout, outSize ); free (out ); return ret; }
size_t cond::Cipher::encrypt | ( | const std::string & | input, |
unsigned char *& | output | ||
) |
Definition at line 62 of file Cipher.cc.
References funct::false, and convertSQLitetoXML_cfg::output.
Referenced by cond::DecodingKey::flush().
{ return bf_process_alloc( reinterpret_cast<const unsigned char*>(input.c_str()), input.size(), output, false );; }
BLOWFISH_CTX* cond::Cipher::m_ctx [private] |