在iOS上,Certificate,Key和Trust Services API包含以下填充类型:
kSecPaddingNone
kSecPaddingPKCS1
kSecPaddingPKCS1MD2
kSecPaddingPKCS1MD5
kSecPaddingPKCS1SHA1
在对用户苹果CDSA邮件列表中称,"kSecPaddingPKCS1 [...]是一样的PKCS#1 1.5".证书,密钥和信任服务参考注释后三种填充类型(kSecPaddingPKCS1MD2
,kSecPaddingPKCS1MD5
和kSecPaddingPKCS1SAH
),"标准ASN.1填充将完成,以及底层RSA操作的PKCS1填充".
kSecPaddingPKCS1
?kSecPaddingPKCS1
仅仅根据RFC 3447的基本RSA运算的原料填充?SecKeyRawSign()
,开发人员是否需要自己使用kSecPaddingPKCS1
并执行ASN.1填充?是否需要ASN.1填充或是否可以省略?任何暗示我指向正确方向的提示都受到高度赞赏.
我已经解决了将XML RSA私钥转换为PEM文件的问题,但是我遇到另一个问题,即在导入P12私钥时我得到空数据.以下是我的步骤:
将PEM文件转换为P12文件
openssl> pkcs12 -export -in rsa.pem -inkey rsa.pem -out rsa.p12 -nocerts
Run Code Online (Sandbox Code Playgroud)将P12文件读入iOS项目
NSString *path = [[NSBundle bundleForClass:[self class]]
pathForResource:@"MyPrivateKey" ofType:@"p12"];
NSData *p12data = [NSData dataWithContentsOfFile:path];
if (![self getPrivateKeyRef])
RSAPrivateKey = getPrivateKeywithRawKey(p12data);
Run Code Online (Sandbox Code Playgroud)导入P12私钥
SecKeyRef getPrivateKeywithRawKey(NSData *pfxkeydata)
{
NSMutableDictionary * options = [[[NSMutableDictionary alloc] init] autorelease];
// Set the public key query dictionary
//change to your .pfx password here
[options setObject:@"MyPassword" forKey:(id)kSecImportExportPassphrase];
CFArrayRef items = CFArrayCreate(NULL, 0, 0, NULL);
OSStatus securityError = SecPKCS12Import((CFDataRef) pfxkeydata,
(CFDictionaryRef)options, &items);
CFDictionaryRef identityDict = CFArrayGetValueAtIndex(items, …
Run Code Online (Sandbox Code Playgroud)