Openssl enc命令

一、简介

enc - 对称加密例程,使用对称密钥对数据进行加解密,特点是速度快,能对大量数据进行处理。算法有流算法和分组加密算法,流算法是逐字节加,由于其容易被破译,现在已很少使用;分组加密算法是将数据分成固定大小的组里,然后逐组进行加密,如DES。分组算法中又有ECB,CBC,CFB,OFB,CTR等工作模式,其中默认选CBC工作模式。

二、语法

openssl enc -ciphername[-in filename] [-out filename] [-pass arg] [-e] [-d] [-a/-base64] [-A] [-k password] [-kfile filename] [-K key] [-iv IV] [-S salt] [-salt] [-nosalt] [-z] [-md] [-p] [-P] [-bufsize number] [-nopad] [-debug] [-none] [-engine id]

选项

-in <file>     input file
-out <file>    output file
-pass <arg>    pass phrase source
-e             encrypt
-d             decrypt
-a/-base64     base64 encode/decode, depending on encryption flag
-k             passphrase is the next argument
-kfile         passphrase is the first line of the file argument
-md            the next argument is the md to use to create a key
                 from a passphrase. See openssl dgst -h for list.
-S             salt in hex is the next argument
-K/-iv         key/iv in hex is the next argument
-[pP]          print the iv/key (then exit if -P)
-bufsize <n>   buffer size
-nopad         disable standard block padding
-engine e      use engine e, possibly a hardware device.

三、实例

1、使用des3算法对文件进行加密,并解密

openssl enc -p -des3 -pass pass:123456 -in test.txt -out cipher.txt 
openssl enc -d -des3 -pass pass:123456 -in cipher.txt -out plain.txt

image

2、加密对数据进行base64编码,并在解密前对数据进行base64解码

openssl enc -p -des3 -a -pass pass:123456 -in test.txt -out cipher.txt 
openssl enc -d -des3 -a -pass pass:123456 -in cipher.txt -out plain.txt

image

原文地址:https://www.cnblogs.com/274914765qq/p/4665750.html