crypto.py 文件源码

python
阅读 29 收藏 0 点赞 0 评论 0

项目:routewatch 作者: nerdalize 项目源码 文件源码
def decrypt(encodedciphertext, secret):
    """
    Basically wraps the cryptography lib to reduce code duplication
    :param encodedciphertext:
    :type encodedciphertext: bytes
    :param secret:
    :type secret: bytes
    :return:
    """
    # Split out the salt from the ciphertext
    ciphertext = b64decode(encodedciphertext)
    salt = ciphertext[:16]
    ciphertext = ciphertext[16:]
    # Regenerates the key by HMACing the secret with the salt
    kdf = PBKDF2HMAC(algorithm=hashes.SHA256(), length=32, salt=salt, iterations=100000, backend=default_backend())
    key = urlsafe_b64encode(kdf.derive(secret))
    # Decrypts the data
    f = Fernet(key)
    data = f.decrypt(ciphertext)
    return data
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号