openssl命令行进行RSA加密解密

实现了在Window控制台使用openssl工具生成rsa私钥和公钥

然后用公钥对于hello.txt文件加密得到enhello.txt文件

最后用私钥对于enhello.txt文件解密得到outhello.txt文件


控制台命令如下:

OpenSSL> genrsa -out rsa_private_key.pem 1024
Generating RSA private key, 1024 bit long modulus
.......+++++
.+++++
e is 65537 (0x010001)
OpenSSL> rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
writing RSA key
OpenSSL> rsautl -encrypt -in hello.txt -inkey rsa_public_key.pem -pubin -out enhello.txt
OpenSSL> rsautl -decrypt -in enhello.txt -inkey rsa_private_key.pem -out outhello.txt
OpenSSL>

文件一览:

 

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
OpenSSL是一个广泛使用的开放源代码工具包,提供加密解密功能。它支持DES和RSA加密算法,可以用来加密解密数据。DES是一种对称加密算法,使用相同的密钥进行加密解密RSA是一种非对称加密算法,使用公钥进行加密,私钥进行解密。 使用OpenSSL进行DES加密解密,首先需要生成一个DES密钥,然后使用该密钥进行加密解密操作。可以使用以下命令生成DES密钥: ``` openssl rand -out des.key 8 ``` 生成的密钥保存在des.key文件中。然后使用该密钥进行加密解密: ``` openssl enc -des -in plaintext.txt -out encrypted.des -kfile des.key openssl enc -d -des -in encrypted.des -out decrypted.txt -kfile des.key ``` 上述命令分别用指定的DES密钥对明文文件plaintext.txt进行加密,然后将加密结果保存到encrypted.des文件中。解密操作则相反,使用相同的DES密钥对加密后的文件进行解密,得到明文文件decrypted.txt。 而要使用RSA算法进行加密解密,首先需要生成RSA密钥对(公钥和私钥),然后使用公钥进行加密,私钥进行解密。可以使用以下命令生成RSA密钥对: ``` openssl genrsa -out private.pem 1024 openssl rsa -in private.pem -pubout -out public.pem ``` 生成的私钥保存在private.pem文件中,公钥保存在public.pem文件中。然后使用公钥进行加密,私钥进行解密: ``` openssl rsautl -encrypt -in plaintext.txt -out encrypted.rsa -inkey public.pem openssl rsautl -decrypt -in encrypted.rsa -out decrypted.txt -inkey private.pem ``` 上述命令分别使用指定的公钥对明文文件plaintext.txt进行加密,然后将加密结果保存到encrypted.rsa文件中。解密操作则相反,使用相同的私钥对加密后的文件进行解密,得到明文文件decrypted.txt。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值