如何用openssl sm2 加密文件

sh/bash/dash/ksh/zsh等Shell脚本
回复
leshui2016
帖子: 5
注册时间: 2020-03-05 11:38

如何用openssl sm2 加密文件

#1

帖子 leshui2016 » 2020-03-07 23:32

deepin@deepin-PC:~$ openssl sm2 -help
Invalid command ‘sm2’; type “help” for a list.
deepin@deepin-PC:~$ openssl sm3 -help
Usage: sm3 [options] [file…]
file… files to digest (default is stdin)
-help Display this summary
-c Print the digest with separating colons
-r Print the digest in coreutils format
-out outfile Output to filename rather than stdout
-passin val Input file pass phrase source
-sign val Sign digest using private key
-verify val Verify a signature using public key
-prverify val Verify a signature using private key
-signature infile File with signature to verify
-keyform format Key file format (PEM or ENGINE)
-hex Print as hex dump
-binary Print in binary form
-d Print debug info
-debug Print debug info
-fips-fingerprint Compute HMAC with the key used in OpenSSL-FIPS fingerprint
-hmac val Create hashed Mac with key
-mac val Create MAC (not necessarily HMAC)
-sigopt val Signature parameter in n:v form
-macopt val Mac algorithm parameters in n:v form or key
-* Any supported digest
-rand val Load the file (s) into the random number generator
-writerand outfile Write random data to the specified file
-engine val Use engine e, possibly a hardware device
-engine_impl Also use engine given by -engine for digest operations
deepin@deepin-PC:~$ openssl sm4 -help
Usage: sm4 [options]
Valid options are:
-help Display this summary
-ciphers List ciphers
-in infile Input file
-out outfile Output file
-pass val Passphrase source
-e Encrypt
-d Decrypt

看了 openssl 源代码,里面有 sm2 的。sm3、sm4 都可以用,sm2 为何用不成,不能用于加密?
网上的人说可以生成用 openssl 生成 sm2 的密钥,就是不知道如何用 openssl sm2 加密文件?
头像
astolia
论坛版主
帖子: 6459
注册时间: 2008-09-18 13:11

Re: 如何用openssl sm2 加密文件

#2

帖子 astolia » 2020-03-08 13:47

openssl目前没办法通过命令行的方式进行sm2加解密。你需要自己写个程序来调用libcrypto库中的sm2_encrypt/sm2_decrypt
https://blog.wandoer.com/note/%E4%BD%BF ... %AF%86.htm
回复