2
对于ECC后的SecKeyGeneratePair
,我尝试用公钥加密明文。 SecKeyEncrypt
返回-4(errSecUnimplemented)。我不确定填充类型是否正确。我在我的xcode中尝试了所有类型,但它们不能很好地工作。有人可以解释为什么SecKeyEncrypt
返回-4?什么是椭圆曲线加密的填充类型
(NSData *)encrypt:(NSString *)plainTextString key:(SecKeyRef)publicKey {
NSData *data = [plainTextString dataUsingEncoding:NSUTF8StringEncoding];
size_t encryptedDataLength = SecKeyGetBlockSize(publicKey);
NSMutableData *encryptedData = [[NSMutableData alloc]
initWithLength:encryptedDataLength];
OSStatus err = SecKeyEncrypt(publicKey,
kSecPaddingOAEP,
[data bytes],
[data length],
[encryptedData mutableBytes],
&encryptedDataLength);
NSLog(@"errEXX: %ld", err);
[encryptedData setLength:encryptedDataLength];
return encryptedData;
}