Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1454977
  • 博文数量: 596
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 173
  • 用 户 组: 普通用户
  • 注册时间: 2016-07-06 15:50
个人简介

在线笔记

文章分类

全部博文(596)

文章存档

2016年(1)

2015年(104)

2014年(228)

2013年(226)

2012年(26)

2011年(11)

分类: 架构设计与优化

2013-05-23 16:48:12

调用RC4函数时,会修改密钥。因此需要两组密钥,一组用来加密,一组用来解密。

  1. #include <openssl/rc4.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>

  5. static unsigned char g_rc4key[16] =
  6. {
  7.       0x2c, 0xb6, 0xa1, 0xe7, 0xe1, 0x0c, 0x50, 0x02,
  8.         0xa5, 0xde, 0xae, 0x7f, 0xe6, 0x05, 0xbd, 0x90,
  9. };

  10. int main()
  11. {
  12.     unsigned char buffer[10];
  13.     unsigned char buffer1[10];
  14.     RC4_KEY m_rc4SendKey, decryKey;
  15.     char str[10] = "123456789";
  16.     int len = 10;

  17.     memset(buffer, 0, 10);
  18.     memset(buffer1, 0, 10);
  19.     RC4_set_key(&m_rc4SendKey, sizeof(g_rc4key), g_rc4key);
  20.     RC4_set_key(&decryKey, sizeof(g_rc4key), g_rc4key);

  21.     RC4(&m_rc4SendKey, len, str, buffer);
  22.     printf("org: %sn", str);

  23.     RC4(&decryKey, len, buffer, buffer1);
  24.     printf("no_cry: %sn", buffer1);

  25.     return 0;
  26. }


阅读(3734) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~