hathor-cpp-scanner/bcrypt.cc

36 lines
922 B
C++

#include <cstdlib>
#include <cstdio>
#include <openssl/blowfish.h>
#include <cstring>
#include <iostream>
#define SIZE 64
int main()
{
unsigned char* in = (unsigned char *)"TestData";
unsigned char* out = (unsigned char*) calloc(SIZE+1, sizeof(char));
unsigned char* out2 = (unsigned char*) calloc(SIZE+1, sizeof(char));
//pData = (int*) calloc (i,sizeof(int));
BF_KEY *key = (BF_KEY*) calloc(1, sizeof(BF_KEY));
std::string result;
/* set up a test key */
BF_set_key(key, SIZE, (const unsigned char*)"TestKey!" );
/* test out encryption */
char buf[sizeof(BF_KEY)];
BF_ecb_encrypt(in, out, key, BF_ENCRYPT);
for(int i=0;i<sizeof(BF_KEY); i++) {
sprintf(buf, "%c", out[i]);
result.append( buf );
}
printf("%s\n", result.c_str());
/* test out decryption */
BF_ecb_encrypt(out, out2, key, BF_DECRYPT);
printf("%s\n", out2);
free(out);
free(out2);
free(key);
return 0;
}