【问题标题】:openssl CMS with ECDH EnvelopedDataopenssl CMS 与 ECDH EnvelopedData
【发布时间】:2015-03-26 14:11:20
【问题描述】:

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

有什么想法吗? TIA。

./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:

【问题讨论】:

  • 有趣,输出是什么样的?别担心,我不会解密受 192 位密钥保护的密文:P
  • OpenSSL 的 Steve Henson 将其解决如下:“RSA 可以在不知道证书的情况下解密,但目前 EC 不能。所以请尝试在解密时包含选项 -recip ecc.crt。”
  • 您可以将其添加为答案。不过有点奇怪,参数标识和公钥都是私钥结构的一部分。
  • 是的 - 这就是让我失望的原因。我猜是因为在 1.0.2 中刚刚添加了对 EC 的支持。感谢您抽出宝贵时间提供帮助!
  • 小提示:CLI 在 StackOverflow 上是(边界)离题。通常这类问题最好在SuperUser 上提出。这是边界,因为 shell 脚本绝对是编程,例如,关于 bash 脚本的问题非常热门。

标签: cryptography openssl elliptic-curve


【解决方案1】:

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!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-29
    • 1970-01-01
    • 1970-01-01
    • 2021-01-30
    • 2019-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多