What is the padding type for Elliptic Curve Crypto

霸气de小男生 提交于 2019-12-12 18:24:44

问题


After SecKeyGeneratePair for ECC, I try to encrypt plaintext by the public key. SecKeyEncrypt returns -4(errSecUnimplemented). I am not sure about the padding type is correct. I tried all the types in my xcode, they don't work as well. Can somebody explain why SecKeyEncrypt returns -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:


Apple's implementation only supports ECDSA, which can be used for signing but not encryption. For information about encrypting using elliptic curves using other schemes see Is it possible to use elliptic curve cryptography for encrypting data?



来源:https://stackoverflow.com/questions/21320363/what-is-the-padding-type-for-elliptic-curve-crypto

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!