- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 iPhone 上使用这个 OpenSSL 代码生成一个 PKCS#12 文件,给定证书/私钥的一些数据。我能够验证此 PKCS#12 在 OpenSSL 上是否可解析,因为当我在代码中检查它时它不会打印出错误。但是,当我将它传输到我的服务器时,它显示:错误:无法验证 PKCS#12 MAC。密码无效?
有谁知道这是为什么?我正在使用相同的密码,即“密码”
- (NSData *)generateP12AsNSData:(NSData *)keyData certificate:(NSData *)certificateData {
//put the certificateData into a X509 certificate
const unsigned char *certificateDataBytes = (const unsigned char*)[certificateData bytes];
X509 *certificateX509 = d2i_X509(NULL, &certificateDataBytes, [certificateData length]);
EVP_PKEY *privateKey;
PKCS12 *p12;
//cast the key data as an unsigned char so that we can convert it to the OpenSSL key format
const unsigned char *bits = (unsigned char *) [keyData bytes];
int length = (int)[keyData length];
privateKey = EVP_PKEY_new();
//convert the unsigned char to OpenSSL Key format
RSA *rsa = NULL;
d2i_RSAPrivateKey(&rsa, &bits, &length);
EVP_PKEY_assign_RSA(privateKey, rsa);
//create the PKCS#12
OpenSSL_add_all_algorithms();
p12 = PKCS12_create("password", "ExtraDeviceP12", privateKey, certificateX509, NULL, 0,0,0,0,0);
//make sure the p12 exists
if(!p12) {
fprintf(stderr, "Error creating PKCS#12 ");
ERR_print_errors_fp(stderr);
return nil;
}
//error checking to make sure we generated the CSR correctly
STACK_OF(X509) *ca = NULL;
EVP_PKEY *parseKey;
X509 *parseCert;
if (!PKCS12_parse(p12, "password", &parseKey, &parseCert, &ca)) {
printf("error parsing PKCS#12 file");
return nil;
}
//convert the PKCS#12 to binary data
//create a new memory BIO. A BIO is used for basic I/O abstraction.
BIO *bio;
bio = BIO_new(BIO_s_mem());
//i2d_PKCS12_bio is used to export a PKCS12 object
i2d_PKCS12_bio(bio, p12);
BUF_MEM *buffer;
BIO_get_mem_ptr(bio, &buffer);
//int bioLen = BIO_pending(&buffer);
char *buff = (char*)malloc(buffer->length);
memcpy(buff, buffer->data, buffer->length - 1);
buff[buffer->length - 1] = 0;
NSData *data = [NSData dataWithBytes:buff length:buffer->length];
NSString *string = [data base64EncodedStringWithOptions:0];
NSLog(@"Base64 PKCS#12: %@", string);
BIO_free_all(bio);
return data;
}
编辑:这是我服务器端用 Javascript 编写的代码。在这种情况下,req.body 是从 iPhone 发送的 NSData。我收到无效密码错误。
var p12b64 = req.body.toString('base64');
var p12Der = forge.util.decode64(pk12b64);
var p12Asn1 = forge.asn1.fromDer(p12Der);
var p12 = forge.pkcs12.pkcs12FromAsn1(p12Asn1, 'password');
最佳答案
尝试以下操作。它向您展示了应该检查某些关键返回值的位置,并且避免了额外的数据拷贝:
BIO *bio = BIO_new(BIO_s_mem());
ASSERT(bio != NULL);
int ret = i2d_PKCS12_bio(bio, p12);
ASSERT(ret == 1);
BUF_MEM *buffer;
BIO_get_mem_ptr(bio, &buffer);
ASSERT(buffer != NULL);
NSData *data = [NSData dataWithBytes:buffer->data length:buffer->length];
BIO_free_all(bio);
您可以在 i2d_PKCS12_bio
man pages 找到 i2d_PKCS12_bio
的文档.
如果需要,您可以对来自 i2d_PKCS12_bio
的二进制数据进行 Base64 编码。参见 Non-printable character after generating random n-byte Base64 string使用 BIO 链并确保 Base64 字符串以 NULL 终止。
关于c++ - PKCS#12 密码无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38383681/
常用的 PKCS 标准有什么用:PKCS#7、PKCS#10 和 PKCS#12? 最佳答案 PKCS#7 允许您使用 X.509 证书对通用数据进行签名和加密。 PKCS#7 格式也可用于存储一个或
我想知道当使用 AES-128-CBC 时,openssl 如何处理可被 8 个字节整除的消息。 openssl 如何检测到没有要删除的填充(PKCS#5/PKCS#7)?特别是当消息以 ASCII
我正在阅读 PKCS 11 文档,但我无法清楚地理解 key 的 CKA_SENSITIVE 属性是什么意思。 更常见的是:我在哪里可以阅读属性描述? 最佳答案 引自 PKCS#11 spec v2.
我想寻求有关使用 cryptography.hazmat.primitives.padding.PKCS7 的帮助Python 类。 解密后,我得到字符串45394700000019770808080
我知道 PKCS#7 = 证书 + 可选原始数据 + PKCS#1 格式的签名 我需要从 PKCS#7 签名中提取 PKCS#1 如何在 C# 中执行此操作。我可以用充气城堡来做这个吗,这是我的实现I
我希望能够使用带有 aws golang SDK 的 AWS SNS 发送 iOS APNS 推送通知。我按照以下说明创建了一个 p12 文件:https://support-aws.s3.amazo
关闭。这个问题需要更多focused .它目前不接受答案。 想改善这个问题吗?更新问题,使其仅关注一个问题 editing this post . 2年前关闭。 Improve this questi
我正在开发一个移动应用程序,它必须验证它收到的一些签名。我拥有我需要的一切——输入数据、公钥和签名。但有一个问题。我使用方法 SHA256withRSA 进行签名验证,其中包含以下几行代码来验证签名:
我有一个 PKCS#5 加密的 PKCS#8 RSA 私钥存储在一个磁盘文件中(最初由 SSLPlus 生成,大约在 1997 年),例如: -----BEGIN ENCRYPTED PRIVATE
是否可以将 PKCS#8 编码的 RSA 私钥转换为 PKCS#1?我知道这可以通过 openssl 轻松完成,但是可以用 Java 完成吗? 最佳答案 使用 BouncyCaSTLe 1.50 Pr
我正在为 Android 实现 Jscep。最初,我尝试了 Jscep for java,效果很好。现在在 Android 中,我使用 SpongyCaSTLe 而不是 BouncyCaSTLe。现在
我正在尝试在 SafeNet HSM 中生成一个 RSA key 对。我为私钥和公钥复制了 PKCS11 中指定的示例模板。当我生成 key 对时,一切正常。但是,当我为私钥指定以下属性值时,C_Ge
密码学在信息安全中扮演着至关重要的角色。为了保护敏感信息、数字身份和网络通信的安全性,密码设备(如硬件安全模块HSM)与应用程序之间的安全通信和互操作性变得至关重要。PKCS#11(Public-K
这玩意折腾了一天,有个老外的代码,公钥用了PKCS#1,私钥用了PKCS#8。调用了不同的API,而我的全是生成的PKCS#8,后面查阅了大量资料和长时间调试程序,才发现了问题,在此记录下。 用Ope
PKCS#12是一种将私钥与其对应的 X.509 证书合并为标准化的单一文件格式的便捷方式。然而,该规范于 1999 年由 RSALabs 发布,并且仅使用 RC4、RC2 和 TripleDES 进
我正在尝试使用 PKCS#7 进行签名和验证签名。我正在阅读《beginning cryptography with java》这本书。我已经编写了示例代码来签名和验证。当我尝试附加签名并将其写入文件
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 想改进这个问题?将问题更新为 on-topic对于堆栈溢出。 4年前关闭。 Improve this qu
使用java加密、签名、解密、验证签名需要遵循哪些步骤? 使用 PKCS#7 算法, java keystore 有什么用?关于 PKCS#7。 最佳答案 第 1 步 使用 keytool 实用程序生
我在 iPhone 上使用这个 OpenSSL 代码生成一个 PKCS#12 文件,给定证书/私钥的一些数据。我能够验证此 PKCS#12 在 OpenSSL 上是否可解析,因为当我在代码中检查它时它
我实际上正在研究一个应该从 PKCS7 mime 加密消息中提取 RecipientInfo 的函数。我想这样做的原因是,我想获取邮件加密的所有邮件地址(或至少是 keyids/指纹)。 嗯 - 我尝
我是一名优秀的程序员,十分优秀!