最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

AES

IT圈 admin 27浏览 0评论

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

总结

希望可以帮助到大家。

发布评论

评论列表 (0)

  1. 暂无评论