base64编解码

来源:互联网 发布:中信淘宝信用卡权益 编辑:程序博客网 时间:2024/06/15 21:42

openssl命令

基本命令格式:

  • BASE64编码:
    – openssl base64 [-e] -in hello.txt ——这里的-e是缺省值,所以可以省略。
    – openssl base64 -in hello.txt > hello.txt.base64
    – openssl base64 -e -in hello.txt -out hello.base64.en
  • BASE64解码:
    – openssl base64 -d -in hello.txt.base64
    – openssl base64 -d -in hello.txt.base64 > hello.txt.base64.de
    – openssl base64 -d -in hello.base64.en -out hello.base64.de

示例一

$ echo -n Hello, world! > hello.txt$ cat hello.txt Hello, world!$ $ $ openssl base64 -in hello.txtSGVsbG8sIHdvcmxkIQ==$ openssl base64 -in hello.txt > hello.txt.base64 $ cat hello.txt.base64SGVsbG8sIHdvcmxkIQ==$ openssl base64 -d -in hello.txt.base64 Hello, world! $ openssl base64 -d -in hello.txt.base64 > hello.txt.base64.de $ cat hello.txt.base64.de$ diff hello.txt hello.txt.base64.de $ 

示例二

$ cat hello.txt Hello, world!$ openssl base64 -e -in hello.txt -out hello.base64.en$ cat hello.base64.en SGVsbG8sIHdvcmxkIQo=$ openssl base64 -d -in hello.base64.en -out hello.base64.de$ diff hello.txt hello.base64.de $ cat hello.base64.de Hello, world!$ 

在线工具

BASE64在线编解码工具:http://www1.tc711.com/tool/BASE64.htm

Python

>>> import base64>>> s = "hello, world!">>> enc = base64.b64encode(s)>>> enc'aGVsbG8sIHdvcmxkIQ=='>>> t = base64.b64decode(enc)>>> t'hello, world!'>>>
原创粉丝点击