我使用OpenSSL创建了一个EC公钥:
openssl ecparam -name prime256v1 -genkey -noout -out ec-key.pem
openssl ec -in ec-key.pem -pubout -out ecpubkey.pem
如何导入它(ecpubkey.pem)并在我的objective-c代码中使用它来验证签名?
答案 0 :(得分:2)
在iOS中使用EC密钥的一种方法是使用第三方库GMEllipticCurveCrypto:https://github.com/ricmoo/GMEllipticCurveCrypto。看看吧。
答案 1 :(得分:0)
这对我有用: 使用打开
创建密钥drawIconAtRotation()
使用openssl生成 der encoded 证书:
openssl ecparam -name prime256v1 -genkey -noout -out ec-key.pem
签署内容
openssl req -new -x509 -key ec-key.pem -outform der -out server.pem -days 730
然后加载证书
openssl dgst -sha256 -sign ec-key.pem content.txt > signature
从证书中提取公钥
NSString *cerPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"server" ofType:@"cer"];
NSData *cerData = [NSData dataWithContentsOfFile:cerPath];
SecCertificateRef certificate = SecCertificateCreateWithData(NULL, (CFDataRef)cerData);
验证签名
SecPolicyRef secPolicy = SecPolicyCreateBasicX509();
SecTrustRef trust;
SecTrustCreateWithCertificates(certificate, secPolicy, &trust);
SecTrustResultType resultType;
SecTrustEvaluate(trust, &resultType);
SecKeyRef publicKey = SecTrustCopyPublicKey(trust);