Elliptic Curve Crypto的填充类型是什么

时间:2014-01-23 22:08:52

标签: ios objective-c encryption elliptic-curve

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

1 个答案:

答案 0 :(得分:2)

Apple的实施仅支持ECDSA,可用于签名但不能加密。有关使用其他方案使用椭圆曲线加密的信息,请参阅Is it possible to use elliptic curve cryptography for encrypting data?