openssl - 使用 prime256v1 私钥加密/解密的 openssl 命令?
问题描述
我想用 EC 私钥加密一条简单的消息,特别是 CMD 的prime256v1;并使用相应的 EC 公钥解密。
我只在非对称加密情况下或使用 ec 公钥加密中找到了 RSA 的参考资料,但我需要使用 ECDSA 算法并使用私钥进行加密。
解决方案
生成一个自签名的 P-256 证书和相关的私钥,如下所示:
openssl ecparam -name prime256v1 -out p256-params.pem
openssl req -x509 -nodes -days 3650 -newkey ec:p256-params.pem -keyout p256-key.pem -out p256-cert.pem
像这样加密文件:
openssl cms -encrypt -binary -aes-256-cbc -in plaintext.dat -out ciphertext.dat p256-cert.pem
像这样解密文件:
openssl cms -decrypt -in ciphertext.dat -out plaintext2.dat -inkey p256-key.pem
签署这样的文件:
openssl cms -sign -binary -in plaintext.dat -out signedtext.dat -inkey p256-key.pem -signer p256-cert.pem -nodetach
验证这样的签名文件:
openssl cms -verify -in signedtext.dat -out plaintext2.dat -CAfile p256-cert.pem
推荐阅读
- django - 如何在 django 的 send_mail 中自定义消息
- c++ - 删除根节点时出现 BST 分段错误
- json - 如何使用json在laravel中制作链接或依赖的select2?
- bash - 用于查找空 Hive 数据库的 Shell 脚本
- antlr - 模棱两可的 ANTLR 语法
- laravel - 如何使用 LARAVEL 防止从同一浏览器但从同一用户凭据的不同选项卡多次登录
- android - 如何使用 Kotlin 将 base64 PDF 字符串解码为 HTML 内容以在 WebView Android 中显示?
- laravel - 中间件不根据角色保护路由
- javascript - 我怎样才能在显示器上得到结果
- reactjs - 开发期间的 React 组件 html 预览