Esempio n. 1
0
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
Esempio n. 2
0
def test_b58decode_value_error():
    with pytest.raises(ValueError):
        b58decode("abcl23")
Esempio n. 3
0
def test_b58decode(decoded, s):
    assert hexlify(b58decode(s)).decode() == decoded