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
评论列表
文章目录