AES
之前帮小伙伴用Python实现了AES-CFB8算法,需要自取
代码如下:
import json
from base64 import b64encode, b64decode
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytesdef cfb_encrypt(data, key, iv=None):if iv is None:iv = get_random_bytes(16)cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8)ct_bytes = cipher.encrypt(data)ct = b64encode(ct_bytes).decode('utf-8')iv = b64encode(iv).decode('utf-8')return encrypt_data, ivdef cfb8_decrypt(ciphertext, iv, key):iv = b64decode(iv)ct = b64decode(ciphertext)cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8)decrypt_data = cipher.decrypt(ct)return decrypt_data
总结
希望可以帮助到大家。
AES
之前帮小伙伴用Python实现了AES-CFB8算法,需要自取
代码如下:
import json
from base64 import b64encode, b64decode
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytesdef cfb_encrypt(data, key, iv=None):if iv is None:iv = get_random_bytes(16)cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8)ct_bytes = cipher.encrypt(data)ct = b64encode(ct_bytes).decode('utf-8')iv = b64encode(iv).decode('utf-8')return encrypt_data, ivdef cfb8_decrypt(ciphertext, iv, key):iv = b64decode(iv)ct = b64decode(ciphertext)cipher = AES.new(key, AES.MODE_CFB, iv, segment_size=8)decrypt_data = cipher.decrypt(ct)return decrypt_data
总结
希望可以帮助到大家。