Cryptodome入门

from Crypto.Cipher import AES 
from Crypto import Random
key=b'1234567887654321'
iv=Random.new().read(AES.block_size)
print(iv)
//b'\x9c\xbc\xf8\xa4\xf0A\x90\xf9\x8d\x88\xaa\xb4\x9d\xd2d\xf2'
cipher=AES.new(key,AES.MODE_CFB,iv=iv)
data='中国'.encode()
msg=cipher.encrypt(data)
print(msg)    //b'\x1e\xa6\xea\xb4b\xe7'
##传递密文   msg
cipher2=AES.new(key,AES.MODE_CFB,iv=iv)
msg2=cipher2.decrypt(msg)
print(msg2)    //b'\xe4\xb8\xad\xe5\x9b\xbd'



print(data)     //b'\xe4\xb8\xad\xe5\x9b\xbd'
print(msg2.decode())     //中国

 

你可能感兴趣的:(加密)