使用openssl进行RSA加解密

一、生成RSA私钥

openssl genrsa -out private.key 1024

二、提前RSA公钥

openssl rsa -in private.key -pubout -out public.key

三、场景一:使用公钥加密,私钥解密

1、使用公钥对明文(hello)加密

openssl rsautl -encrypt -in hello -inkey public.key -pubin -out hello.en

2、使用私钥对密文(hello.en)解密

openssl rsautl -decrypt -in hello.en -inkey private.key -out hello.de

四、场景二:使用私钥加密(签名),公钥解密(验证)

1、使用私钥对明文(hello)加密

openssl rsautl -sign -in hello -inkey private.key -out hello.en

2、使用公钥对密文(hello.en)解密

openssl rsautl -verify -in hello.en -inkey public.key -pubin -out hello.de
posted @ 2020-08-25 16:41  wmate  阅读(408)  评论(0编辑  收藏  举报