天天看點

base64編解碼openssl指令線上工具Python

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.txt
SGVsbG8sIHdvcmxkIQ==
$ openssl base64 -in hello.txt > hello.txt.base64 
$ cat hello.txt.base64
SGVsbG8sIHdvcmxkIQ==
$ 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!'
>>>