OpenSSL des加密函数des_ecb_encrypt的用法

10808阅读 0评论2010-09-03 leibniz_zsu
分类:LINUX

/*
gcc -o des-basic des-basic.c -lcrypto
*/
#include
#include

int main(int argc,char **argv)
{
    DES_cblock key;
    /**//* DES_random_key(&key); */ /**//* generate a random key */
    DES_string_to_key("pass", &key);
   
    DES_key_schedule schedule;
    DES_set_key_checked(&key, &schedule);
   
    const_DES_cblock input = "hehehe";
    DES_cblock output;

    printf("cleartext:%s ", input);
   
    DES_ecb_encrypt(&input, &output, &schedule, DES_ENCRYPT);
    printf("Encrypted! ");

    printf("ciphertext:");
    int i;
    for (i = 0; i < sizeof(input); i++)
        printf("%02x", output[i]);
    printf(" ");
   
    DES_ecb_encrypt(&output, &input, &schedule, DES_DECRYPT);
    printf("Decrypted! ");
    printf("cleartext:%s ", input);
   
    return 0;
}
上一篇:《openssl 编程》之 RSA(转)
下一篇:linux c 不回显输入密码