base64 编解码

1
2
3
4
base64 a.txt
base64 -d a.txt
echo -n "hello"|base64
echo -n "aGVsbG8="|base64 -d

测试

1
2
3
4
5
6
7
$ echo -n "hello" > a.txt
$ cat a.txt
hello%
$ cat a.txt|base64
aGVsbG8=
$ echo -n "aGVsbG8="|base64 -d
hello%

消息摘要

下面以字符串 hello 和文件 a.txt 为例

注意:echo -n 代表不发送换行符; 不带参数默认发送换行符。 cat 默认会增加换行

1
2
3
4
5
md5 a.txt
md5 -s hello

shasum -a 1/256/512 a.txt
echo -n "hello"|shasum -a 1/256/512

Linux 下有 md5sum

1
2
md5sum a.txt
echo -n 123456 | md5sum

openssl

1
2
3
4
5
6
7
8
openssl md5 a.txt
echo -n "hello"|openssl md5

openssl sha1/256/512 a.txt
echo -n "hello"|openssl sha1/256/512

echo -n "hello"|openssl base64
echo -n "aGVsbG8="|openssl base64 -d

AES/DES3 加密解密

AES 有五种加密模式:CBC、ECB、CTR、OCF、CFB,以 CBC 加密模式为例,对明文 “plaintext”进行加密,结果以 base64 编码格式输出,可以加 -k 选项指定明文密钥,也可以直接回车按提示输入密钥。

1
echo -n "plaintext"|openssl aes-128-ecb -base64

对明文 ‘plaintext’ 进行 triple-DES 加密,使用密钥 123456,输出结果以 base64 编码格式输出。

1
echo 'plaintext' |openssl des3 -k 123456 -base64