Cryptography 带有ECDH信封数据的openssl CMS

Cryptography 带有ECDH信封数据的openssl CMS,cryptography,openssl,elliptic-curve,Cryptography,Openssl,Elliptic Curve,我正在使用openssl 1.0.2a,特别是对ECC的CMS支持。 作为测试,我正在做一个简单的加密和解密。 我给出了一个RSA示例,作为已知的良好工作示例/健全性测试。 ECC示例失败 有什么想法吗?蒂亚 ./openssl version OpenSSL 1.0.2a 19 Mar 2015 echo -n 12345678123456781234567812345678 > sess.txt # 32 byte plaintext #RSA works ./openssl ge

我正在使用openssl 1.0.2a,特别是对ECC的CMS支持。 作为测试,我正在做一个简单的加密和解密。 我给出了一个RSA示例,作为已知的良好工作示例/健全性测试。 ECC示例失败

有什么想法吗?蒂亚

./openssl version
OpenSSL 1.0.2a 19 Mar 2015

echo -n 12345678123456781234567812345678 > sess.txt # 32 byte plaintext

#RSA works
./openssl genrsa -out rsa.key 2048
./openssl req -x509 -new -key rsa.key -out rsa.crt
./openssl cms -encrypt -in sess.txt -out rsaencsess.bin -outform PEM rsa.crt
./openssl cms -decrypt -in rsaencsess.bin -out rsadecsess.txt -inform PEM -inkey rsa.key
#AOK.

#EC fails
  ./openssl ecparam -name prime192v1 -genkey -out ecc.key
  ./openssl req -x509 -new -key ecc.key -out ecc.crt
  ./openssl cms -encrypt -in sess.txt -out encsess.bin -outform PEM ecc.crt
  ./openssl cms -decrypt -in encsess.bin -out decsess.txt -inform PEM -inkey ecc.key
Error decrypting CMS structure
error:06065064:digital envelope routines:EVP_DecryptFinal_ex:bad decrypt:evp_enc.c:529:

OpenSSL的Steve Henson将其解析为:“RSA可以在不知道证书的情况下解密,但目前EC无法解密。因此,请尝试在解密时包含选项-recip ecc.crt

现在可以这样做了:

./openssl ecparam -name prime192v1 -genkey -out ecc.key
./openssl req -x509 -new -key ecc.key -out ecc.crt
./openssl cms -encrypt -in sess.txt -out encsess.bin -outform PEM ecc.crt
./openssl cms -decrypt -in encsess.bin -out decsess.txt -inform PEM -inkey ecc.key -recip ecc.crt # NOTE "-recip ecc.crt" is currently required else it won't work!

有趣的是,输出是什么样子的?别担心,我不会解密一个受192位密钥保护的密文:POpenSSL的Steve Henson将其解析为:“RSA可以在不知道证书的情况下解密,但目前EC无法解密。因此,请尝试在解密时包含选项-recip ecc.crt。“您可以添加该选项作为答案。尽管有点奇怪,参数ident和公钥都是私钥结构的一部分。是的,这让我很吃惊。我想这是因为对EC的支持刚刚在1.0.2中添加。感谢您花时间提供帮助!小提示:CLI是(边界)StackOverflow上的离题问题。通常这类问题最好是直接问。这是边界问题,因为shell脚本肯定是在编程,例如,有关bash脚本的问题就非常离题。