Created
August 28, 2016 12:32
-
-
Save abdilahrf/481102bc4a028b4561fd1a7220476937 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from Crypto.Cipher import AES | |
import sys | |
import os | |
#Initial Vector ... | |
IV_SIZE = 16 | |
#Block size .. | |
BLOCK_SIZE = 16 | |
#Key adalah kunci untuk enkirpsinya | |
key = sys.argv[1] | |
#Setting mode enkripsi ke ECB | |
mode = AES.MODE_ECB | |
#Lakukan random untuk mendapatkan iv dengan os.urandom | |
iv = os.urandom(IV_SIZE) | |
# Buat objek aes ... | |
aes = AES.new(key, mode, iv) | |
# Baca file yang ada fi argv[2] sebagai f | |
with open(sys.argv[2], "rb") as f: | |
data = f.read() | |
# Buat padding dari "16 - len(data) % 16" | |
padding = BLOCK_SIZE - len(data) % BLOCK_SIZE | |
# jadi banyak \x00 ... | |
data += padding * "\x00" | |
# encrypt file nya | |
encrypted = aes.encrypt(data) | |
# simpan hasil encrypt ke argv[2] + .encrypted | |
with open(sys.argv[2] + ".encrypted", "wb") as f: | |
f.write(encrypted) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment