zoukankan      html  css  js  c++  java
  • libtomcrypt 1.06 RC4例子


    #include "stdafx.h"
    #include <tomcrypt.h>
    #include "RSACrypto.h"
    int main(int argc, char* argv[])
    {

     prng_state prng;
     unsigned char buf[32];
     int err;
     //加密
     if ((err = rc4_start(&prng)) != CRYPT_OK) {
      printf("RC4 init error: %s\n", error_to_string(err));
      exit(-1);
     }
     /* use "key" as the key */
     if ((err = rc4_add_entropy((unsigned char*)"key", 3, &prng)) != CRYPT_OK) {
      printf("RC4 add entropy error: %s\n", error_to_string(err));
      exit(-1);
     }
     /* setup RC4 for use */
     if ((err = rc4_ready(&prng)) != CRYPT_OK) {
      printf("RC4 ready error: %s\n", error_to_string(err));
      exit(-1);
     }
     /* encrypt buffer */
     char *strmsg2="123456";
     strcpy((char*)buf,strmsg2);
     unsigned long outlen=strlen(strmsg2);
     if (rc4_read(buf, outlen, &prng) != outlen) {
      printf("RC4 read error\n");
      exit(-1);
     }

     printf("%s\n\n",buf);
     rc4_done(&prng);

     //解密
     if ((err = rc4_start(&prng)) != CRYPT_OK) {
      printf("RC4 init error: %s\n", error_to_string(err));
      exit(-1);
     }
     /* use "key" as the key */
     if ((err = rc4_add_entropy((unsigned char*)"key", 3, &prng)) != CRYPT_OK) {
      printf("RC4 add entropy error: %s\n", error_to_string(err));
      exit(-1);
     }
     /* setup RC4 for use */
     if ((err = rc4_ready(&prng)) != CRYPT_OK) {
      printf("RC4 ready error: %s\n", error_to_string(err));
      exit(-1);
     }
     if (rc4_read(buf, outlen, &prng) != outlen) {
      printf("RC4 read error\n");
      exit(-1);
     }
     printf("%s",buf);

    return 0;

    }

  • 相关阅读:
    CSDN博客 专用备份工具
    discuz 7.0 uc 同步登录方法
    delphi 子窗体最大化
    OO系统分析员之路用例分析系列(8)如何编写一份完整的UML需求规格说明书[整理重发]
    delphi 抓取网页内容的程序
    delphi messagebox 使用技巧
    windows mobile下实现程序安装和卸载
    纯真IP库算法
    delphi idhttp 使用方法
    最近评论回复汇总
  • 原文地址:https://www.cnblogs.com/ahuo/p/1177291.html
Copyright © 2011-2022 走看看