Encryption and Obfuscation

codakcodak·2026년 1월 6일

Security

목록 보기
1/4

Encryption

  • 비밀 키 또는 공개/개인 키와 같은 암호학적 키를 사용하여,
    평문(plaintext)을 암호문(ciphertext)으로 변환함으로써
    키 없이는 내용을 해석할 수 없도록 하는 수학적 변환 과정
  • Symmetric-Key Encryption
  • Asymmetric-Key Encryption

Obfuscation

  • 데이터의 존재 자체를 감추기 위해,
    다른 무해한 매체(이미지, 오디오, 비디오, 트래픽 등) 안에
    정보를 은닉(conceal)하는 기술
  • Data Masking
  • Tokenization
  • Steganography
    • Image
    • Video
    • Audio

특징

구분EncryptionSteganography
핵심 목적기밀성은닉
공격자가 보는 것암호문정상 데이터
키의 역할필수선택적
해독 가능성해독 불가즉시 노출

"Encryption과 Steganography는 모두 데이터를 보호하기 위한 기술이지만,

Encryption은 데이터를 수학적으로 보호하는 기술이고,

Obfuscation은 이해를 어렵게 만들어 노출 위험을 줄이는 기법이다."

Symmetric-Key Encryption 실습

코드

from cryptography.fernet import Fernet

key = Fernet.generate_key()
cipher = Fernet(key)


print("Secret Key:", key)


plaintext = b"Hello Security+"
print("Plaintext:", plaintext)


ciphertext = cipher.encrypt(plaintext)
print("Ciphertext:", ciphertext)


decrypted = cipher.decrypt(ciphertext)
print("Decrypted:", decrypted)

출력

Secret Key: b'o0bqtDCZB9600KQ_DaJeRf_2Sp8OsHyQAWgqVWLYhBs='
Plaintext: b'Hello Security+'
Ciphertext: b'gAAAAABpXNCKl_2EpnjQEJjjYVirMh8mOeNoa3991iuwBZdND0HJy8A9rkous8DvPQ7RPSq7DD6Yq22F1oYffHrrj_E-taSJrg=='
Decrypted: b'Hello Security+'

Image-Steganography-Encode 실습

from PIL import Image


img = Image.open("input.png").convert("RGB")
pixels = img.load()

secret_message = "HELLO"


binary = "".join(format(ord(c), "08b") for c in secret_message) + "00000000"


width, height = img.size
idx = 0


for y in range(height):
    for x in range(width):
        if idx >= len(binary):
            break

        bit = int(binary[idx])
        r, g, b = pixels[x, y]

        r = 255 if bit == 1 else 0

        pixels[x, y] = (r, g, b)
        idx += 1

img.save("encoded_image.png")
print("✅ Visible steganography image created: stego_visible.png")

원본 이미지

인코딩된 이미지

왼쪽 위의 LSB를 대체하는 방식으로 난독화된 부분을 확인할 수 있다.

Image-Steganography-Decoder 실습

Code

from PIL import Image


img = Image.open("encoded_image.png").convert("RGB")
pixels = img.load()

width, height = img.size
bits = ""

for y in range(height):
    for x in range(width):
        r, g, b = pixels[x, y]

        bit = "1" if r >= 128 else "0"
        bits += bit


message = ""


for i in range(0, len(bits), 8):

    byte = bits[i : i + 8]
    if len(byte) < 8:
        break

    if byte == "00000000":
        break

    message += chr(int(byte, 2))

print("✅ Decoded message:", message)
profile
숲을 보는 코더

0개의 댓글