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;

    }

  • 相关阅读:
    QT 5 安装 vs2017 后,出现找不到 rc.exe 问题
    git push -f
    使用druid连接池的超时回收机制排查连接泄露问题
    git 记住密码
    postgresql c library use
    jvm内存溢出分析
    Maven中使用本地JAR包
    执行Git命令时出现各种 SSL certificate problem 的解决办法
    transformer模型计算图
    jieba分词单例模式及linux权限不够情况下tmp_dir自定义
  • 原文地址:https://www.cnblogs.com/ahuo/p/1177291.html
Copyright © 2011-2022 走看看