SecKeyGeneratePair
之后对于ECC,我尝试用公钥加密明文。 SecKeyEncrypt
返回 -4(errSec 未实现)。我不确定填充类型是否正确。我尝试了 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;
}
最佳答案
Apple 的实现仅支持 ECDSA,它可用于签名但不能用于加密。有关使用其他方案使用椭圆曲线进行加密的信息,请参阅 Is it possible to use elliptic curve cryptography for encrypting data?
关于ios - 椭圆曲线加密的填充类型是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21320363/