资源简介
通过读取PEM密钥,调用openssl开发RSA1024的加密解密,包括私钥的加解密和公钥的加解密。
代码片段和文件信息
#include
#include
#include
#include
#include
#include
#include
#define OPENSSLKEY “test.key“
#define PUBLICKEY “public2.pem“
#define PRIVATEKEY “private.pem“
int my_encrypt(char *str char *path_key unsigned char *caRspCode); //加密
int my_decrypt(char *str const int ilen char *path_key unsigned char *caRspData); //解密
int my_encryptPrivate(char *str char *path_key unsigned char *caRspData); //解密
int my_decryptPrivate(char *str const int ilen char *path_key unsigned char *caRspData); //解密
/**
* Use EVP to base64 encode the input byte array to readable text
*/
int base64(const unsigned char *inputBuffer int inputLen unsigned char *base64)
{
EVP_ENCODE_CTX ctx;
int base64Len = (((inputLen+2)/3)*4) + 1; // base64 text length
int pemLen = base64Len + base64Len/64; // PEM adds a newline every 64 bytes
//char base64 = new char[pemLen];
int result;
EVP_EncodeInit(&ctx);
EVP_EncodeUpdate(&ctx (unsigned char *)base64 &result (unsigned char *)inputBuffer inputLen);
EVP_EncodeFinal(&ctx (unsigned char *)&base64[result] &result);
return pemLen;
}
/**
* Use EVP to base64 decode the input readable text to original bytes
*/
int unbase64(char *input int length int* outLen unsigned char * orgBuf)
{
EVP_ENCODE_CTX ctx;
int orgLen = (((length+2)/4)*3) + 1;
//unsigned char* orgBuf = new unsigned char[orgLen];
int result tmpLen;
EVP_DecodeInit(&ctx);
EVP_DecodeUpdate(&ctx (unsigned char *)orgBuf &result (unsigned char *)input length);
EVP_DecodeFinal(&ctx (unsigned char *)&orgBuf[result] &tmpLen);
result += tmpLen;
*outLen = result;
return result;
}
int main(int argc char * argv[])
{
int iLen iLen2;
int i;
int iRet;
unsigned char caRspData[2048];
char caDecRDat[2048];
char caOutBuf[2048];
unsigned char caOutBuf2[1024];
char *source=“i like dancing !“;
char *ptr_en*ptr_de;
if(argc < 2)
{
printf(“argc < 2 err“);
return 0;
}
printf(“source is :%s\n“source);
memset(caRspData 0x00 sizeof(caRspData));
iLen = my_encryptPrivate(source argv[1] caRspData);
if(iLen > 0)
{
printf(“S1:“);
for(i = 0; i < iLen; i++)
{
printf(“%02X“ caRspData[i]);
}
printf(“ %d\n“ iLen);
}
else
return -1;
iRet = 0;
if(iLen > 0)
{
memset(caOutBuf 0x00 sizeof(caOutBuf));
//iRet = base64_encode(caRspData iLen caOutBuf);
iRet = base64(caRspData iLen caOutBuf);
//iRet = base64_encodeA(caRspData iLen caOutBuf);
if(iRet < 0)
{
printf( “base64_encode failed\n“);
return -1;
}
printf(“\noutdata:%s\n“ caOutBuf);
}
memset(caRspData 0x00 sizeof(caRspData));
//iLen = base64_decode(caOutBuf caRspData);
iLen2 = 0;
iLen = unbase64(caOutBuf iRet &iLen2 caRspData);
//iLen = base64_decodeA(caOutBuf
- 上一篇:stm32f407+FFT浮点运算例程
- 下一篇:MSComm_VS2010
相关资源
- RSA非对称加密
- RSA加密解密网络课程设计
- Chirp Scaling算法处理RADARSAT-1数据_shar
- tc8 x64 openssl库文件补丁
- arm-linux-gcc-4.3.2交叉编译
- RSA混合加密系统源码
- 默认使用DES加密聊天信息的SocketChat(
- stm32在ubuntu linux下开发测试源文件
- 《openssl编程》当前完整版本
- compiler gcc5.h
- RSA算法加密解密源码及程序完整的工
- 缺少compiler-gcc5.h文件
- Linux 实验8
- LSBRSA的图片隐藏技术.zip
- tomcat,https加密方式jsse.openssl
- ibm rational rsa 9.5最新版本完美破解
- Indy SSL Lib For Delphi7 OpenSSL
- PoorSakura4改钱存档相关
- 测试gcc优化效果的代码
- openssl文档
- openssl加密通信服务器、客户端代码
- security.js 实现前台加密
- openssl安装及命令
- easyrsa-2.2.2.zip
- RADARSAT_RDA.rar
- Corel.All.Products.Universal.Keygens.by.CORE.v
- RADARSAT_wKA.rar
- rsa加解密,jsencrypt.min.js库,分段 和
- rsa加解密,jsencrypt.min.js库
- mingw-get-setup
评论
共有 条评论