Openssl 加解密文件
使用openssl 的命令行进行文件的加密与解密过程,主要有两种方式:
- openssl 指定加密/解密算法加密
- openssl 指定公钥/私钥文件加密
openssl 指定加密/解密算法加密
To Encrypt:
openssl enc -e -aes-256-cbc -in un_encrypted.data -out encrypted.data
- 1
To Decrypt:
openssl enc -d -aes-256-cbc -in encrypted.data -out un_encrypted.data
- 1
Note: 1. You will be prompted for a password when encrypting or decrypt.
openssl 指定公钥/私钥文件加密
The following commands are relevant when you work with RSA keys:
- openssl genrsa: Generates an RSA private keys.
- openssl rsa: Manage RSA private keys (includes generating a public key from it).
- openssl rsautl: Encrypt and decrypt files with RSA keys.
Get the public key
Let the other party send you a certificate or their public key. If they send to a certificate you can extract the public key using this command:
openssl rsa -in certificate.pem -out publickey.pem -outform PEM -pubout
- 1
Generate the random password file
Use the following command to generate the random key:
openssl rand -base64 128 -out key.bin
- 1
Do this every time you encrypt a file. Use a new key every time!
Encrypt the file with the random key
Use the following command to encrypt the large file with the random key:
openssl enc -aes-256-cbc -salt -in largefile.pdf -out largefile.pdf.enc -pass file:./bin.key
- 1
The file size doesn’t grows that much:
$ ls -larth
-rw-r--r-- 1 user group 40M Nov 9 21:14 Linux-Voice-Issue-020.pdf
-rw-r--r-- 1 user group 40M Nov 9 22:03 Linux-Voice-Issue-020.pdf.enc
- 1
- 2
- 3
It’s encrypted however:
$ file Linux-Voice-Issue-020.pdf
Linux-Voice-Issue-020.pdf: PDF document, version 1.4
- 1
- 2
$ file Linux-Voice-Issue-020.pdf.enc
Linux-Voice-Issue-020.pdf.enc: data
- 1
- 2
Encrypt the random key with the public keyfile
Use the following command to encrypt the random keyfile with the other persons public key:
openssl rsautl -encrypt -inkey publickey.pem -pubin -in key.bin -out key.bin.enc
- 1
You can safely send the key.bin.enc
and the largefile.pdf.enc
to the other party.
You might want to sign the two files with your public key as well.
Decrypt the random key with our private key file
If you want to decrypt a file encrypted with this setup, use the following command with your privte key (beloning to the pubkey the random key was crypted to) to decrypt the random key:
openssl rsautl -decrypt -inkey privatekey.pem -in key.bin.enc -out key.bin
- 1
This will result in the decrypted random key we encrypted the file in.
Decrypt the large file with the random key
Once you have the random key, you can decrypt the encrypted file with the decrypted key:
openssl enc -d -aes-256-cbc -in largefile.pdf.enc -out largefile.pdf -pass file:./bin.key
- 1
This will result in the decrypted large file.
openssl 程序实现公钥/私钥加解密
生成私钥:
openssl genrsa -out pri_test.key 2048
生成公钥:
openssl rsa -in pri_test.key -pubout > pub_test.key
Run the following command to retrieve your SSH RSA fingerprint (-l
means "list" instead of create a new key, -f
means "filename"):
$ ssh-keygen -lf /path/to/ssh/key
So for example, on my machine the command I ran was:
$ ssh-keygen -lf ~/.ssh/id_rsa.pub
Concrete example (if you use an RSA public key):
$ ssh-keygen -lf ~/.ssh/id_rsa.pub
2048 00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff /Users/username/.ssh/id_rsa.pub (RSA)
With newer versions of ssh-keygen, run ssh-keygen -E md5 -lf <fileName>
if you want the same format as old (thanks Lloyd Dewolf)
Openssl 加解密文件的更多相关文章
- (8) openssl rsautl(签名/验证签名/加解密文件)和openssl pkeyutl(文件的非对称加密)
rsautl是rsa的工具,相当于rsa.dgst的部分功能集合,可用于生成数字签名.验证数字签名.加密和解密文件. pkeyutl是非对称加密的通用工具,大体上和rsautl的用法差不多,所以此处只 ...
- curses-键盘编码-openssl加解密【转】
本文转载自;https://zhuanlan.zhihu.com/p/26164115 1.1 键盘编码 按键过程:当用户按下某个键时, 1.键盘会检测到这个动作,并通过键盘控制器把扫描码(scan ...
- Java DES 加解密文件
import com.mchange.v2.io.DirectoryDescentUtils; import javax.crypto.Cipher;import javax.crypto.Ciphe ...
- OpenSSL加解密
http://www.caole.net/diary/des.html Table of Contents OpenSSL - DES Summary DES使用的例子 另一个带注释的例子 另一段Co ...
- vim 命令加解密文件
加密文件 vim file :X (大写X,是加密 ,小写x是保存) 输入密码: 确认密码: 解除密码: vim file :set key= :wq 命令模式下,输入 /word 后回车,即查找w ...
- php OpenSSL 加解密
2018-1-6 17:10:19 星期六 $data = '123456'; $openssl_method = 'AES-256-CBC'; $openssl_iv_length = openss ...
- openssl在多平台和多语言之间进行RSA加解密注意事项
首先说一下平台和语言: 系统平台为CentOS6.3,RSA加解密时使用NOPADDING进行填充 1)使用C/C++调用系统自带的openssl 2)Android4.2模拟器,第三方openssl ...
- 用mp3stego来加密与解密文件的几次尝试
用法来自实验吧的"Canon"隐写题目的灵感. 先来简单的聊一下这道题目,打开题目后发现了一个mp3文件,除此之外还有一枚压缩包.然而压缩包是加密的,看来我们需要通过解出来mp3里 ...
- PHP加密解密方法,使用openssl加密解密
/** * des 加密算法 */ function do_mencrypt($input, $key) { if (!function_exists("mcrypt_module_open ...
随机推荐
- [TJOI2013]奖学金 乱搞
[TJOI2013]奖学金 乱搞 从\(c\)个二元组\((v,w)\)中选出\(n\)个,使其\(v\)的中位数最大的同时使\(w\)和小于等于\(f\),求这个中位数 有点意思.有点像二分答案的思 ...
- linux系列(十八):locate命令
1.命令格式: locate [选择参数] [样式] 2.命令功能: locate指令和find找寻档案的功能类似,但locate是透过update程序将硬盘中的所有档案和目录资料先建立一个索引数据库 ...
- 小程序自定义底部tab
首页wxml的代码: <view class="nav" hover-class="none"> <view class="inde ...
- mysql解压文件安装
mysql.zip版本的安装教程 MySQL zip版本安装 一直以来都习惯了使用MySQL安装文件(.exe),今天下载了一个.zip版本的MySQL,安装过程中遇到了一些问题,如下: 1.在M ...
- kafka 讲讲acks参数对消息持久化的影响
目录 (0)写在前面 (1)如何保证宕机时数据不丢失? (2)多副本冗余的高可用机制 (3)多副本之间数据如何同步? (4)ISR到底指的什么东西? (5)acks参数的含义? (6)最后的思考 ...
- Visual C++ 6.0精简绿色版下载及简单使用教程
Visual C++ 6.0精简绿色版下载及简单使用教程 Microsoft Visual C++简介 Visual Studio 是微软公司推出的开发环境,Visual Studio 可以用来创建 ...
- IOS开发环境
当我们需要帮一些人学习IOS的时候,可以翻阅下这篇文章,我有个同学对IOS开发不太了解,用语言描述该怎么做的时候显得不够具体,或者全部需要我帮忙操作,又会占用我们的时间,如果每个人都这么要求的话,那么 ...
- STM32F4 LTDC
首先配置同步时序先看参考手册 下面看一个实际例子,一块439的开发板 设置: 配置时序 LTDC_InitStruct.LTDC_HorizontalSync = ; /* */ LTDC_InitS ...
- Java设计模式:代理模式(转)
代理(Proxy)是一种设计模式,提供了对目标对象另外的访问方式;即通过代理对象访问目标对象.这样做的好处是:可以在目标对象实现的基础上,增强额外的功能操作,即扩展目标对象的功能.这里使用到编程中的一 ...
- SQL-W3School-函数:SQL GROUP BY 语句
ylbtech-SQL-W3School-函数:SQL GROUP BY 语句 1.返回顶部 1. 合计函数 (比如 SUM) 常常需要添加 GROUP BY 语句. GROUP BY 语句 GROU ...