Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1630642
  • 博文数量: 584
  • 博客积分: 13857
  • 博客等级: 上将
  • 技术积分: 11883
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-16 09:34

分类: LINUX

2010-09-03 15:01:58

/*
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;
}
阅读(10731) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~