def decrypt(ciphertext, password): version = ciphertext[:1] ciphertext = b58decode(ciphertext[1:].decode()) if version == b"1": salt = ciphertext[: argon2id.SALTBYTES] # 16 encrypted = ciphertext[argon2id.SALTBYTES :] key = argon2id.kdf( SecretBox.KEY_SIZE, # 32 password, salt, opslimit=argon2id.OPSLIMIT_SENSITIVE, # 4 memlimit=argon2id.MEMLIMIT_SENSITIVE, # 1073741824 ) else: raise VersionError("Invalid version byte; received {}".format(version)) box = SecretBox(key) plaintext = box.decrypt(encrypted) return plaintext
def test_b58decode_value_error(): with pytest.raises(ValueError): b58decode("abcl23")
def test_b58decode(decoded, s): assert hexlify(b58decode(s)).decode() == decoded