#include
#include
#include
#include
#include
#pragma comment(lib,"libeay32.lib")
#include "iostream"
using namespace std;
/*
int main(int argc, char **argv)
{
unsigned char buf[16];
memset(buf,1,sizeof(buf));
strcpy((char *)buf, "zengraoli");
cout <
unsigned char buf2[16];
unsigned char buf3[16];
unsigned char aes_keybuf[32];
memset(aes_keybuf,0,sizeof(aes_keybuf));
strcpy((char *)aes_keybuf, "zeng");
cout <
AES_KEY aeskey;
AES_set_encrypt_key(aes_keybuf,256,&aeskey);
AES_encrypt(buf,buf2,&aeskey);
cout <
memset(aes_keybuf,0,sizeof(aes_keybuf));
strcpy((char *)aes_keybuf, "zeng2");
cout <
AES_set_decrypt_key(aes_keybuf,256,&aeskey);
AES_decrypt(buf2,buf3,&aeskey);
cout <
if(memcmp(buf,buf3,sizeof(buf))==0)
printf("test success\r\n");
else
printf("test fail\r\n");
}*/
//#include
//
//int main()
//{
// RSA *r;
//
// int bits=512,ret;
//
// unsigned long e = RSA_3;
//
// BIGNUM *bne;
//
// r = RSA_generate_key(bits, e, NULL, NULL);
//
// RSA_print_fp(stdout, r, 11);
//
// RSA_free(r);
//
// bne = BN_new();
//
// ret = BN_set_word(bne,e);
//
// r = RSA_new();
//
// ret = RSA_generate_key_ex(r, bits, bne, NULL);
//
// if(ret!=1)
// {
// printf("RSA_generate_key_ex err!\n");
//
// return -1;
// }
//
// RSA_free(r);
//
// return 0;
//
//}
int main(int argc, char **argv)
{
char code[64]={0};
int codelen=sizeof(code);
memcpy_s(code,64,"This is secrect",15);
printf("before encrypt :%s\r\n",code);
unsigned char * outbuffer=(unsigned char *)malloc(codelen);
//用指定密钥对一段内存进行加密,结果放在outbuffer中
RC4_KEY rc4_key;
RC4_set_key(&rc4_key,7,(unsigned char *)"iampassword");
RC4(&rc4_key,codelen,(unsigned char *)code,outbuffer);
printf("after encrypt :%s\r\n",outbuffer);
//用指定密钥对outbuffer中的密文进行解密,结果放回原来的内存
memset(code,0,sizeof(code));
RC4_set_key(&rc4_key,7,(unsigned char *)"iampassword");//这里必须再次设置密钥
RC4(&rc4_key,codelen,outbuffer,(unsigned char *)code);
printf("after decrypt :%s\r\n",code);
free(outbuffer);
return 0;
}