68user's page 掲示板

Prev< No. 3592> Next  [最新発言に戻る] [過去ログ一覧]
No. 3592 # 68user 2004/03/02 (火) 22:56:24
メモ。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;
}

Prev< No. 3592> Next  [最新発言に戻る] [過去ログ一覧]