RC4加密解密

调用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. }


阅读(1626) | 评论(0) | 转发(0) |
0

上一篇:Handling oprofile sample buffer overflows

下一篇:4 Linux Commands To View Page Faults Statistics

相关热门文章
  • socket中的短连接与长连接,心...
  • Haproxy、Keepalived双主高可...
  • Tomcat的性能与最大并发(1000)...
  • Nginx深入详解之日志
  • socket编程的同步、异步与阻塞...
  • linux dhcp peizhi roc
  • 关于Unix文件的软链接
  • 求教这个命令什么意思,我是新...
  • sed -e "/grep/d" 是什么意思...
  • 谁能够帮我解决LINUX 2.6 10...
给主人留下些什么吧!~~
评论热议

你可能感兴趣的:(RC4加密解密)