DEV Community

drake
drake

Posted on

某Bit数据解密算法

核心部分

from Crypto.Cipher import AES
from Crypto.Util.Padding import unpad
import base64


def Ie(e, n, iv):
    """
    e: 被加密的数据 data
    n: AES 解密用到的key(加密的秘钥) necromancer
    iv: 初始化向量(AES CBC模式加密增加随机性加密的一个参数)
    """
    # Convert base64 encoded string to bytes
    e = base64.b64decode(e)

    # Parse key and IV
    key = n.encode('utf-8')
    iv = iv.encode('utf-8')  # Assuming this is the default IV if not provided

    # Create AES cipher in CBC mode
    cipher = AES.new(key, AES.MODE_CBC, iv=iv)

    # Decrypt the data
    decrypted = cipher.decrypt(e)

    # Unpad the decrypted data
    unpadded = unpad(decrypted, AES.block_size)

    # Convert to string
    return unpadded.decode('utf-8')
Enter fullscreen mode Exit fullscreen mode

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up