AES (128 비트) CBC 모드에서 파일을 암호화 (암호 해독) 할 수있는 작은 조각의 코드를 발견했습니다. 해독에도 완벽하게 작동하므로 OpenSSL은 (물론) 내 파일의 암호를 해독 할 수는 있지만 불가 능해 보입니다. 나는파이썬과 OpenSSL : 암호 해독 할 수 없습니다.
import os, random, struct
from Crypto.Cipher import AES
def encrypt_file(key, in_filename, out_filename=None, chunksize=64*1024):
""" Encrypts a file using AES (CBC mode) with the
given key.
key:
16, 24 or 32 bytes long
in_filename:
Name of the input file
out_filename:
If None, '<in_filename>.enc' will be used.
chunksize:
Sets the size of the chunk which the function
uses to read and encrypt the file.
Chunksize must be divisible by 16.
"""
if not out_filename:
out_filename = in_filename + '.enc'
iv = ''.join(chr(random.randint(0, 0xFF)) for i in range(16))
encryptor = AES.new(key, AES.MODE_CBC, iv)
filesize = os.path.getsize(in_filename)
with open(in_filename, 'rb') as infile:
with open(out_filename, 'wb') as outfile:
outfile.write(struct.pack('<Q', filesize))
outfile.write(iv)
while True:
chunk = infile.read(chunksize)
if len(chunk) == 0:
break
elif len(chunk) % 16 != 0:
chunk += ' ' * (16 - len(chunk) % 16)
outfile.write(encryptor.encrypt(chunk))
오류 "읽기 오류 입력 파일"같은 지금 시간이 얻을 : "오류 읽기 입력 파일". 어떻게 가능할까요? 내가 사용하는 명령은 다음과 같습니다.
openssl aes-128-cbc -d -in test_enc.txt -out test_dec.txt
왜 작동하지 않습니까?
어 감사합니다. 이제 기본 형식이 달랐습니다. 정말 고맙습니다 –