椭圆曲线加密的填充类型是什么? [英] What is the padding type for Elliptic Curve Crypto

查看:196
本文介绍了椭圆曲线加密的填充类型是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于ECC, SecKeyGeneratePair 之后,我尝试通过公钥加密纯文本。 SecKeyEncrypt 返回-4(errSecUnimplemented)。我不知道填充类型是否正确。我尝试了我的xcode中的所有类型,它们不工作。有人可以解释为什么 SecKeyEncrypt 返回-4?

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


推荐答案

Apple的实现只支持ECDSA,它可以用于签名而不是加密。有关使用其他方案使用椭圆曲线加密的信息,请参阅是否可以使用椭圆曲线加密来加密数据?

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?

这篇关于椭圆曲线加密的填充类型是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆