리눅스에서는 base64 명령으로 base64 인코딩, 디코딩을 쉽게 할 수 있다.

 

1.  문자열 인코딩, 디코딩

1

2

3

4

5

6

7

// base64 encoding (with new_line)

# echo 'hello world' | base64

aGVsbG8gd29ybGQK

 

// base64 decoding

# echo 'aGVsbG8gd29ybGQK' | base64 --decode

hello world

 

이 때 주의할 점은 개행(\n)이 함께 인코딩 된다는 점이다.

개행을 제외하여 인코딩을 하고자 할 경우에는 -n 옵션을 추가하여 인코딩을 한다.

1

2

3

4

5

6

7

// base64 encoding (without new_line)

# echo 'hello world' | base64

aGVsbG8gd29ybGQ=

 

// base64 decoding

# echo 'aGVsbG8gd29ybGQ=' | base64 --decode

hello world#

 

2. 파일 인코딩, 디코딩

파일을 이용하여 인코딩, 디코딩을 할 수 있다.

1

2

3

4

5

6

7

// base64 encoding

# echo 'hello world' | base64 > hello.txt

# cat hello.txt

aGVsbG8gd29ybGQK

// base64 decoding

# base64 -di hello.txt

hello world

+ Recent posts