2017-05-23 5 views
0

Hallo, bevor ich die IV vor (die entschlüsselte Wert von IV ich glaube es) der entschlüsselten Zeichenfolge war. Jetzt bekomme ich nicht die Zeichenfolge ... Wie kann ich diese Arbeit machen, wurde jetzt stundenlang versucht, ...PyCrypto nicht ordnungsgemäß drucken

Mein Code:

from Crypto.Cipher import AES 
    import hashlib 
    import base64 
    import os 
    import string 

    iv = os.urandom(16) 
    key = hashlib.sha256(b'mypassword123').digest() 
    plaintext = (b'the password is totally not secure') 
    cipher = AES.new(key, AES.MODE_CFB, iv) 
    ciphertext = iv + cipher.encrypt(plaintext) 
    print (ciphertext) 
    print ("IV = ",iv) 
    ciphertext = ciphertext.split(iv) 
    ciphertext = str(ciphertext)[1].strip() 
    plaintext = cipher.decrypt(ciphertext) 
    print (plaintext) 

Antwort

0

encrypt wird cipher ändern, müssen Sie machen ein neues; und str wird byte-repr(byte), ändern unten wie:

a=b'xxx' 
str(a) # "b'xxx'" 

from Crypto.Cipher import AES 
import hashlib 
import base64 
import os 
import string 

iv = os.urandom(16) 
key = hashlib.sha256(b'mypassword123').digest() 
plaintext = (b'the password is totally not secure') 
cipher = AES.new(key, AES.MODE_CFB, iv) 
ciphertext = iv + cipher.encrypt(plaintext) 
print (ciphertext) 
print ("IV = ",iv) 
ciphertext = ciphertext.split(iv) 
ciphertext = ciphertext[1] 
cipher2 = AES.new(key, AES.MODE_CFB, iv) 
plaintext = cipher2.decrypt(ciphertext) 
print (plaintext) 

Detail sehen pycrypto