Commit 9369aa7b authored by Vincent Texier's avatar Vincent Texier

[fix] #74 Fix decrypt_seal crash with binary data

parent 40b94813
......@@ -384,6 +384,6 @@ class AsciiArmor:
:param signing_key: SigningKey instance created from credentials
:return:
"""
message = signing_key.decrypt_seal(base64.b64decode(ascii_armor_message))
data = signing_key.decrypt_seal(base64.b64decode(ascii_armor_message))
return message
return data.decode('utf-8')
......@@ -89,11 +89,11 @@ class PublicKey(libnacl.public.PublicKey):
"""
return Base58Encoder.encode(self.pk)
def encrypt_seal(self, message: Union[str, bytes]) -> bytes:
def encrypt_seal(self, data: Union[str, bytes]) -> bytes:
"""
Encrypt message with a curve25519 version of the ed25519 public key
Encrypt data with a curve25519 version of the ed25519 public key
:param message: Message to encrypt
:param data: Bytes data to encrypt
"""
curve25519_public_key = libnacl.crypto_sign_ed25519_pk_to_curve25519(self.pk)
return libnacl.crypto_box_seal(ensure_bytes(message), curve25519_public_key)
return libnacl.crypto_box_seal(ensure_bytes(data), curve25519_public_key)
......@@ -105,17 +105,17 @@ class SigningKey(libnacl.sign.Signer):
key.pubkey = Base58Encoder.encode(key.vk)
return key
def decrypt_seal(self, message: bytes) -> str:
def decrypt_seal(self, data: bytes) -> bytes:
"""
Decrypt message with a curve25519 version of the ed25519 key pair
Decrypt bytes data with a curve25519 version of the ed25519 key pair
:param message: Encrypted message
:param data: Encrypted data
:return:
"""
curve25519_public_key = libnacl.crypto_sign_ed25519_pk_to_curve25519(self.vk)
curve25519_secret_key = libnacl.crypto_sign_ed25519_sk_to_curve25519(self.sk)
return libnacl.crypto_box_seal_open(message, curve25519_public_key, curve25519_secret_key).decode('utf-8')
return libnacl.crypto_box_seal_open(data, curve25519_public_key, curve25519_secret_key)
@classmethod
def from_pubsec_file(cls: Type[SigningKeyType], path: str) -> SigningKeyType:
......
......@@ -29,7 +29,7 @@ if __name__ == '__main__':
# Decrypt the message!
try:
message = signing_key_instance.decrypt_seal(encrypted_message)
message = signing_key_instance.decrypt_seal(encrypted_message).decode('utf-8')
print("Decrypted message:")
except ValueError as error:
message = str(error)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment