openssl 加密(encrypt)、解密(decrypt)、签名(sign)、验证(verify)

一、使用openssl rsautl 进行加密、解密、签名、验证

javascript 复制代码
[kyzjj@yyzc-zjjcs04 openssl]$ openssl rsautl --help
Usage: rsautl [options]
-in file        input file
-out file       output file
-inkey file     input key
-keyform arg    private key format - default PEM
-pubin          input is an RSA public
-certin         input is a certificate carrying an RSA public key
-ssl            use SSL v2 padding
-raw            use no padding
-pkcs           use PKCS#1 v1.5 padding (default)
-oaep           use PKCS#1 OAEP
-sign           sign with private key
-verify         verify with public key
-encrypt        encrypt with public key
-decrypt        decrypt with private key
-hexdump        hex dump output
-engine e       use engine e, possibly a hardware device.
-passin arg    pass phrase source
[kyzjj@yyzc-zjjcs04 openssl]$

二、使用私钥签名openssl rsautl -sign

javascript 复制代码
[kyzjj@yyzc-zjjcs04 openssl]$ cat test
hello world
[kyzjj@yyzc-zjjcs04 openssl]$ openssl rsautl -sign  -inkey private.key  -in test -out sign-test
[kyzjj@yyzc-zjjcs04 openssl]$

三 、使用公钥验证openssl rsautl -verify

javascript 复制代码
[kyzjj@yyzc-zjjcs04 openssl]$ openssl rsautl -sign  -inkey private.key  -in test -out sign-test
[kyzjj@yyzc-zjjcs04 openssl]$ openssl rsautl -verify  -inkey  public.key  -pubin    -in sign-test
hello world
[kyzjj@yyzc-zjjcs04 openssl]$

上述方式可以确认身份,如果我用这个公钥能解密,那一定是你发送的,因为私钥只有你有

四、使用公钥加密

kyzjj@yyzc-zjjcs04 openssl\]$ openssl rsautl -encrypt -inkey public.key -pubin -in test -out en-test \[kyzjj@yyzc-zjjcs04 openssl\]$ # 五、使用私钥解密 \[kyzjj@yyzc-zjjcs04 openssl\]$ openssl rsautl -decrypt -inkey private.key -in en-test hello world \[kyzjj@yyzc-zjjcs04 openssl\]$

相关推荐
糖~醋排骨9 分钟前
FW防火墙的配置
linux·服务器·网络
2301_7809438439 分钟前
linux 对文件打补丁(Patch)
linux·运维·服务器
Lam㊣1 小时前
服务器端口转发的方法
linux·服务器
ChangYan.1 小时前
Windows命令行(cmd)下快速查找文件路径(类似Linux下find命令)
linux·运维·服务器
tao3556671 小时前
VS Code登录codex,报错(os error 10013)
java·服务器·前端
小杰帅气1 小时前
神秘的环境变量和进程地址空间
linux·运维·服务器
胖咕噜的稞达鸭1 小时前
进程间的通信(1)(理解管道特性,匿名命名管道,进程池,systeam V共享内存是什么及优势)重点理解代码!
linux·运维·服务器·数据库
爱吃生蚝的于勒2 小时前
【Linux】进程间通信之匿名管道
linux·运维·服务器·c语言·数据结构·c++·vim
SHolmes18542 小时前
Python all函数 判断是否同时满足多个条件
java·服务器·python
inksci2 小时前
Python 中使用 SQL 连接池
服务器·数据库·python