11 char*
k =
const_cast<char*
>(key.c_str());
24 unsigned int j =
sizeof(
uInt32);
26 unsigned int output_size=0;
27 for (
unsigned int i=0;
i < input_size;
i+=(j*2)){
30 output = (
unsigned char*) malloc( output_size );
31 memset(output, 0, output_size);
33 for (
unsigned int i=0;
i < input_size;
i+=(j*2)) {
37 if( input_size >
i+j ){
39 if( input_size >
i+2*j ){
48 if(nl) memcpy(&L, input+
i, nl);
49 if(nr) memcpy(&R, input+
i+j, nr);
55 memcpy(output+
i, &L, j);
56 memcpy(output+
i+j, &R, j);
63 return bf_process_alloc( reinterpret_cast<const unsigned char*>(input.c_str()), input.size(),
output,
false );;
67 unsigned char*
out = 0;
68 size_t outSize = bf_process_alloc( input, inputSize, out,
true );
69 char* sout =
reinterpret_cast<char*
>(
out);
71 size_t soutSize = strlen( sout );
72 if( soutSize < outSize ){
81 unsigned char*
out = 0;
82 size_t outSize = bf_process_alloc( reinterpret_cast<const unsigned char*>(input.c_str()), input.size(),
out,
false );
84 size_t b64size =
base64_encode_alloc( reinterpret_cast<const char*>(out), outSize, &b64out );
95 throwException(
"Input provided is not a valid base64 string.",
"Cipher::b64decrypt");
97 std::string ret = decrypt( reinterpret_cast<const unsigned char*>(input), inputSize );
void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
void Blowfish_Decrypt(BLOWFISH_CTX *ctx, uInt32 *xl, uInt32 *xr)
void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen)
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)
size_t bf_process_alloc(const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
size_t base64_encode_alloc(const char *in, size_t inlen, char **out)
std::string b64encrypt(const std::string &input)
#define base64_decode_alloc(in, inlen, out, outlen)
void throwException(std::string const &message, std::string const &methodName)
std::string b64decrypt(const std::string &input)