이 pycryptodome 물론 3.4.2TypeError : 바이트를 str에 연결할 수 없습니다. 암호화
를 사용하여, 파이썬 3 AES 암호화 텍스트를 암호화/해독하려고 Pycrypto AES, 나는 '인터넷에서이 방법을 발견하고 내 요구에 대한 변경을 시도하고 모든 I 점점 오류가 발생합니다. 여기
코드입니다 :def aes():
#aes
print('1.Шифруем')
print('2.Дешифруем')
c = input('Ваш выбор:')
if int(c) == 1:
#shifr
os.system('clear')
print('Шифруем значит')
print('Введите текст, который хотите зашифровать')
text = input()
with open('Aes/plaintext.txt', 'wb') as f:
f.write(text.encode('utf-8'))
BLOCK_SIZE = 16
PADDING = '{'
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
secret = os.urandom(BLOCK_SIZE)
with open('Aes/secret.bin', 'wb') as f:
f.write(secret)
cipher = AES.new(secret, AES.MODE_CFB)
with open('Aes/plaintext.txt', 'rb') as f:
text = f.read()
encoded = EncodeAES(cipher, text)
with open('Aes/ciphertext.bin', 'wb') as f:
f.write(encoded)
print (encoded)
if int(c) == 2:
os.system('clear')
print('Дешифруем значит')
PADDING = '{'
with open('Aes/ciphertext.bin', 'rb') as f:
encoded = f.read()
with open('Aes/secret.bin', 'rb') as keyfile:
secret = keyfile.read()
DecodeAES = lambda c, e: c.decrypt(base64.b64decode(e)).rstrip(PADDING)
cipher = AES.new(secret, AES.MODE_CFB)
decoded = DecodeAES(cipher, encoded)
with open('Aes/plaintext.txt', 'w') as f:
f.write(str(decoded))
print(decoded)
하지만 일부 텍스트를 해독하기 위해 노력하고있어 때, 나는이 오류를 얻을 : 사실, 난 람다 무엇을 모르는
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 699, in runfile
execfile(filename, namespace)
File "/usr/lib/python3/dist-packages/spyderlib/widgets/externalshell/sitecustomize.py", line 88, in execfile
exec(compile(open(filename, 'rb').read(), filename, 'exec'), namespace)
File "/home/tukanoid/Desktop/Enc_dec2/Enc_dec.py", line 475, in <module>
aes()
File "/home/tukanoid/Desktop/Enc_dec2/Enc_dec.py", line 178, in aes
encoded = EncodeAES(cipher, text)
File "/home/tukanoid/Desktop/Enc_dec2/Enc_dec.py", line 166, in <lambda>
EncodeAES = lambda c, s: base64.b64encode(c.encrypt(pad(s)))
File "/home/tukanoid/Desktop/Enc_dec2/Enc_dec.py", line 162, in <lambda>
pad = lambda s: s + (BLOCK_SIZE - len(s) % BLOCK_SIZE) * PADDING
TypeError: can't concat bytes to str
을하지만, 나는이 오류로 인해이 오류가 발생한다고 생각합니다. 감사.
[TypeError : 가능한 문자열을 str에 연결하여 python3을 사용하려고 시도 할 수 없습니다.] (http://stackoverflow.com/questions/25042212/typeerror-cant-concat-bytes-to-str-trying-to -use-python3), 모든 곳에서 바이트를 사용해야합니다. –