From 9efb63154b17e8cbfeb3e7d506a800a501d9aa9c Mon Sep 17 00:00:00 2001 From: Roland Eigelsreiter Date: Thu, 23 Nov 2023 07:43:24 +0100 Subject: [PATCH] updated readme --- README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 95117ec..35fb985 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,17 @@ $associatedData = "Some data 😋 文 This data is not contained in the encrypt $encrypted = Ascon::encryptToHex($key, $message, $associatedData); $decrypted = Ascon::decryptFromHex($key, $encrypted, $associatedData); -// raw usage (the original implementation with raw values) +// key must be 16 bytes or 20 bytes, depending on variant $key = [0x90, 0x80, 0x70, 0x60, 0x50, 0x40, 0x30, 0x20, 0x10, 0xAA, 0x90, 0x90, 0x90, 0x90, 0xCC, 0xEF]; +// nonce must be 16 bytes and should always be random bytes, you must use same nonce for encrypt and decrypt the same message $nonce = random_bytes(16); +// this is the text you want to encrypt $plaintext = "Hi, i am a secret message!"; -$associatedData = "Some data the will not be encrypted but verified along the plaintext (Decryption will fail if you not provide the exact same data)"; +// associated data is not being encrypted, but is taken into account in the ciphertext +// this means, you can only decrypt when you pass the exact same associated data to the decrypt function as well +// so you can make sure that associated data and plaintext is not manipulated for given encrypted message +// this is optional and can be an empty string +$associatedData = "Some data to pass to encryption and decryption - This data is not contained in the ciphertext output."; $ciphertextByteArray = Ascon::encrypt($key, $nonce, $associatedData, $plaintext); $plaintextDecrypted = Ascon::decrypt($key, $nonce, $associatedData, $ciphertextByteArray); ```