12 char*
k =
const_cast<char*
>(key.c_str());
24 assert(input_size != 0);
27 unsigned int j =
sizeof(
uInt32);
29 unsigned int output_size=0;
36 for (
unsigned int i=0;
i < input_size;
i+=(j*2)){
39 output = (
unsigned char*) malloc( output_size );
40 memset(output, 0, output_size);
42 for (
unsigned int i=0;
i < input_size;
i+=(j*2)) {
46 if( input_size >
i+j ){
48 if( input_size >
i+2*j ){
57 if(nl) memcpy(&L, input+
i, nl);
58 if(nr) memcpy(&R, input+
i+j, nr);
64 memcpy(output+
i, &L, j);
65 memcpy(output+
i+j, &R, j);
80 if( !inputSize )
return "";
81 unsigned char*
out =
nullptr;
84 for( i=0;i<outSize; i++ ) {
85 if( out[i]==0 )
break;
88 char* sout =
reinterpret_cast<char*
>(
out);
92 for( soutSize=0; soutSize<outSize; soutSize++)
if( out[soutSize]==0 )
break;
94 if( soutSize < outSize ){
106 if( input.empty() )
return "";
107 unsigned char*
out =
nullptr;
108 size_t outSize =
bf_process_alloc( reinterpret_cast<const unsigned char*>(input.c_str()), input.size(),
out,
false );
109 char* b64out =
nullptr;
110 size_t b64size =
base64_encode_alloc( reinterpret_cast<const char*>(out), outSize, &b64out );
118 if( b64in.empty() )
return "";
119 char*
input =
nullptr;
120 size_t inputSize = 0;
122 throwException(
"Input provided is not a valid base64 string.",
"Cipher::b64decrypt");
124 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)
void throwException(const std::string &message, const std::string &methodName)
static std::string const input
size_t encrypt(const std::string &input, unsigned char *&output)
size_t base64_encode_alloc(const char *in, size_t inlen, char **out)
Cipher(const std::string &key)
#define base64_decode_alloc(in, inlen, out, outlen)
size_t bf_process_alloc(const unsigned char *input, size_t input_size, unsigned char *&output, bool decrypt=false)
std::string b64encrypt(const std::string &input)
std::string decrypt(const unsigned char *input, size_t inputSize)
std::string b64decrypt(const std::string &input)