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;
}