メモ。blowfish による暗号化 & 復号化。 #include <stdio.h> #include <openssl/blowfish.h> int main(int argc, char *argv[]){ BF_KEY key; unsigned char keybuf[]="SECRETKEY!"; unsigned char plain[128]="This is plain!"; unsigned char encrypted[128]; unsigned char decrypted[128]; unsigned char ivec[8]; BF_set_key(&key, strlen(keybuf), keybuf); printf("plain=[%s]\n", plain); memset(ivec, 0, sizeof(ivec)); BF_cbc_encrypt(plain, encrypted, strlen(plain), &key, ivec, BF_ENCRYPT); printf("encrypted=[%s]\n", encrypted); memset(ivec, 0, sizeof(ivec)); BF_cbc_encrypt(encrypted, decrypted, strlen(plain), &key, ivec, BF_DECRYPT); printf("decrypted=[%s]\n", decrypted); return 0; } |