base64

Utilities

인코딩 및 디코딩

개요 base64

base64 모듈은 Python 표준 라이브러리의 일부이며 이진 데이터를 ASCII 텍스트로 인코딩하고 다시 디코딩하는 기능을 제공합니다. Base64 인코딩은 HTML에 이미지 삽입, 이메일에 첨부 파일 인코딩, JSON API로 바이너리 데이터 전송, 인증 토큰 생성 등 컴퓨팅의 모든 곳에서 사용됩니다.

base64는 내장 Python 모듈이므로 가져오기나 micropip 다운로드 없이PyRun에서 즉시 작동합니다. 데이터 인코딩, 토큰 구조 및 바이너리에서 텍스트로의 변환 패턴을 이해하기 위해 탐색할 수 있는 훌륭한 모듈입니다.

코드 및 실행 출력

바이너리 데이터를 텍스트로 인코딩, 디코딩 및 검사합니다.

Base64 Encoding에디터에서 실행
import base64
import json

original = "Hello from PyRun!"
encoded = base64.b64encode(original.encode()).decode()
print("Original :", original)
print("Base64   :", encoded)

decoded = base64.b64decode(encoded).decode()
print("Decoded  :", decoded)

url_safe = base64.urlsafe_b64encode(b"data for a URL: /path?q=1&v=2").decode()
print("\nURL-safe:", url_safe)

payload = {"user": "alice", "role": "admin", "exp": 9999999999}
token = base64.b64encode(json.dumps(payload).encode()).decode()
print("\nJWT-style token:", token)
print("Decoded payload:", json.loads(base64.b64decode(token)))

관련 패키지

권장 Python 리소스

관련 대화형 튜토리얼, 치트 시트, 코드 비교를 통해 지식을 확장하세요.