RSA非对称加密初体验

2018-10-10  本文已影响0人  cystone

概述

区块链离不开非对称加密,本文章将简单介绍一下非对称加密的一些基本概念,体验密钥的生成和加密解密的过程。

基本概念

加解密初体验

生成一个密钥:

$ openssl genrsa -out test.key 1024

根据密钥生成公钥:

$ openssl rsa -in test.key -pubout -out test_pub.key

随意创建一个hello的文本文件,写入一些字符。然后加密该文件:

$ echo "Hello RSA!" > hello.txt
$ openssl rsautl -encrypt -in hello.txt -inkey test_pub.key -pubin -out hello.en

解密文件并查看:

$ openssl rsautl -decrypt -in hello.en -inkey test.key -out hello.de
$ cat hello.de

正常情况下,解密结果应该和原文件一致。

参考文献:

  1. https://blog.csdn.net/ly0303521/article/details/53391741
  2. https://www.cnblogs.com/littleatp/p/5878763.html
上一篇 下一篇

猜你喜欢

热点阅读