调用RC4函数时,会修改密钥。因此需要两组密钥,一组用来加密,一组用来解密。
-
#include <openssl/rc4.h>
-
#include <stdio.h>
-
#include <stdlib.h>
-
#include <string.h>
-
-
static unsigned char g_rc4key[16] =
-
{
-
0x2c, 0xb6, 0xa1, 0xe7, 0xe1, 0x0c, 0x50, 0x02,
-
0xa5, 0xde, 0xae, 0x7f, 0xe6, 0x05, 0xbd, 0x90,
-
};
-
-
int main()
-
{
-
unsigned char buffer[10];
-
unsigned char buffer1[10];
-
RC4_KEY m_rc4SendKey, decryKey;
-
char str[10] = "123456789";
-
int len = 10;
-
-
memset(buffer, 0, 10);
-
memset(buffer1, 0, 10);
-
RC4_set_key(&m_rc4SendKey, sizeof(g_rc4key), g_rc4key);
-
RC4_set_key(&decryKey, sizeof(g_rc4key), g_rc4key);
-
-
RC4(&m_rc4SendKey, len, str, buffer);
-
printf("org: %sn", str);
-
-
RC4(&decryKey, len, buffer, buffer1);
-
printf("no_cry: %sn", buffer1);
-
-
return 0;
-
}
阅读(3794) | 评论(0) | 转发(0) |