파이썬[Python]: base64 - b64encode 함수
파이썬(Phthon): base64 모듈 b64encode 함수(function)
/// 설명
Base64를 사용하여 바이트 객체를 인코딩합니다.
URL 또는 filesystem의 안전을 위하여 바이트 객체 altchars(길이=2)가 사용됩니다. altchars가 None이면 표준 Base64를 사용합니다.
※ 형식
base64.b64encode(bytes, altchars=None)
reference
https://docs.python.org/3/library/base64.html#module-base64
URL 또는 filesystem의 안전을 위하여 바이트 객체 altchars(길이=2)가 사용됩니다. altchars가 None이면 표준 Base64를 사용합니다.
※ 형식
base64.b64encode(bytes, altchars=None)
reference
https://docs.python.org/3/library/base64.html#module-base64
/// 예제
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | from base64 import * test_str = 'Is This a string0?' test_bytes = bytes(test_str, 'utf-8') test_encoded = b64encode(test_bytes) print('plain text : ' + test_str) # plain text : Is This a string0? print('bytes :', test_bytes) # bytes : b'Is This a string0?' print('base64 encoded:', test_encoded) # bytes : b'Is This a string0?' print() # Base64 Table 62='+', 63='/' test_bytes = bytes(test_str, 'utf-8') test_altchars = b'-_' # '+' -> '-', '/' -> '_' test_encoded = b64encode(test_bytes, test_altchars) print('plain text : ' + test_str) # plain text : Is This a string0? print('bytes :', test_bytes) # bytes : b'Is This a string0?' print('base64 encoded:', test_encoded) # base64 encoded: b'SXMgVGhpcyBhIHN0cmluZzA_' | cs |
* 실행환경: Microsoft Windows 10 Homes
* 인터프리터: 파이썬(Python 3.9)
– 당신을 응원합니다. –
댓글
댓글 쓰기