int testPKCS7()
{
printf("testPKCS7 BEGIN ........\n");
char strP12[8192 + 1] = { 0 };
int strP12Len = -1;
PKCS12* p12 = NULL;
BIO * m_pBio = NULL;
strP12Len = HSM_ReadFile("cacert1.pfx", "rb", strP12, 8192);
printf("strP12Len:[%d]\n", strP12Len);
m_pBio = BIO_new_mem_buf(strP12, strP12Len);
if (m_pBio == NULL)
{
return -2;
}
p12 = d2i_PKCS12_bio(m_pBio, NULL);
if (p12 == NULL)
{
return -3;
}
//OpenSSL_add_all_algorithms();
//EVP_add_alg_module();
EVP_PKEY *pkey=NULL;
X509 *x509=NULL;
STACK_OF(X509) *ca = NULL;
if (!PKCS12_parse(p12, "11111111", &pkey, &x509, &ca))
{
fprintf(stderr, "Error parsing PKCS#12 file\n");
ERR_print_errors_fp(stderr);
return -2;
}
PKCS12_free(p12);
BIO *bio = BIO_new(BIO_s_mem());
BIO_puts(bio,"1111");
int flag = PKCS7_DETACHED|PKCS7_NOSMIMECAP;
PKCS7* pkcs7 = PKCS7_sign(x509, pkey, ca, bio, flag);
if(pkcs7 == NULL)
{
printf("pkcs7 IS NULL ........\n");
ERR_print_errors_fp(stderr);
return -3;
}
unsigned char *der;
unsigned char *derTmp;
unsigned long derlen;
derlen = i2d_PKCS7(pkcs7,NULL);
der = (unsigned char *) malloc(derlen);
memset(der,0,derlen);
derTmp = der;
i2d_PKCS7(pkcs7,&derTmp);
printf("pkcs7 SIGN ok ........\n");
char pubder[8192+1] = {0};
int pubderlen = 0;
pubderlen = HSM_ReadFile("gmsslsm2.der", "rb", pubder, 8192);
printf("pubderlen:[%d]\n", pubderlen);
BIO * m_pBio1 = NULL;
m_pBio1 = BIO_new_mem_buf(pubder, pubderlen);
if (m_pBio1 == NULL)
{
return -2;
}
printf("m_pBio1 is not null \n");
X509 *x5091 = NULL;
x5091= d2i_X509_bio(m_pBio1, NULL);
if (x5091 == NULL) {
ERR_print_errors_fp (stderr);
return -4;
}
/*unsigned char *retBuf[1024*8];
int retBufLen = sizeof(retBuf);
memset(retBuf, 0, sizeof(retBuf));
decodeBase64(cipherText, (void *)retBuf, &retBufLen);*/
BIO* vin = BIO_new_mem_buf(der,derlen);
PKCS7 *p7 = d2i_PKCS7_bio(vin,NULL);
STACK_OF(X509) *stack=sk_X509_new_null();
sk_X509_push(stack,x5091);
BIO *bio1 = BIO_new(BIO_s_mem());
BIO_puts(bio1,"1111");
int err = PKCS7_verify(p7, stack, NULL,bio1, NULL, PKCS7_NOVERIFY);
if (err != 1) {
ERR_print_errors_fp (stderr);
return -5;
}
printf("err:[%d] \n", err);
return 1;
}
不牛逼的人
- 粉丝: 0
- 资源: 3
最新资源
- ssm基于JAVA WEB技术大健康综合咨询问诊平台的设计与实现+jsp.zip
- ssm基于java web的网上书城系统的设计与实现+vue.zip
- 静态代码测试-QAC度量指标的详细解析与应用
- ssm基于HTML的出租车管理系统+jsp.zip
- ssm基于 Java Web 的校园驿站管理系统+jsp.zip
- ssm基于bs模式的医院在线挂号预约系统的设计与实现+jsp.zip
- ssm会议管理系统ssm.zip
- ssm化妆品配方及工艺管理系统的设计与实现+jsp.zip
- MATLABSimulink 扩展卡尔曼EKF 电池SOC估计 仿真模型 BMS系统仿真
- ssm会员管理系统+jsp.zip
- ssm固定资产管理系统+jsp.zip
- ssm海鲜自助餐厅系统+vue.zip
- css中cursor属性详解PDF
- ssm国学文化网站的设计与制作+jsp.zip
- ssm公司项目管理系统设计与实现+jsp.zip
- ssm工贸学生信息管理系统+jsp.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页