我试图用一个静态库进行RSA加密,这个库不能包含一个应用程序包,这意味着我不能包含一个public_key.der文件。
因此,我试图将.der文件信息硬编码到RSA类中的字节数组中,并从中生成加密密钥,但是每当我调用SecCertificateCreateWithData时,我都会得到一个nil结果。
字节数组:
const char bytes[] = "3082 02b0 3082 0219 a003 0201 0202 0900 f4da 4db7 a151 5877 300d 0609 2a86 4886 f70d 0101...9aa2";然后创建NSData并尝试创建一个证书:
NSData *publicKeyFileContent = [NSData dataWithBytes:bytes length:sizeof(bytes)];
if (publicKeyFileContent == nil) {
NSLog(@"%s Could not read public key", __PRETTY_FUNCTION__);
return nil;
}
certificate = SecCertificateCreateWithData(kCFAllocatorDefault, ( __bridge CFDataRef)publicKeyFileContent);
if (certificate == nil) {
NSLog(@"%s Could not generate certificate", __PRETTY_FUNCTION__);
return nil;
}发布于 2014-05-28 21:47:42
您使用的字节是键的可读的表示形式,而不是键本身。
正确的关键数据如下所示:
const char bytes[] = {
0x30, 0x82, 0x02, 0xb0, 0x30, 0x82, 0x02, 0x19, ...
};(比较一下字符串表示中的第一个字节,3082 02b0 3082 0219。)
https://stackoverflow.com/questions/23922351
复制相似问题