Skip to content

Commit

Permalink
added more demos
Browse files Browse the repository at this point in the history
  • Loading branch information
brainfoolong committed Nov 23, 2023
1 parent e949c65 commit 902a803
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ $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 of basic methods
// 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
Expand All @@ -55,6 +56,9 @@ $plaintext = "Hi, i am a secret message!";
$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);

var_dump(Ascon::hash('Testmessage'));
var_dump(Ascon::mac($key, 'Testmessage'));
```

## Performance and PHP limitations (No showstopper, but you should take notice)
Expand Down
6 changes: 5 additions & 1 deletion demo/raw-usage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@
'ciphertextHex' => Ascon::byteArrayToHex($ciphertextByteArray),
'plaintextDecrypted' => Ascon::byteArrayToStr($plaintextDecrypted),
'verifiedDecryption' => Ascon::strToByteArray($plaintext) === $plaintextDecrypted,
]);
]);


var_dump(Ascon::hash('Testmessage'));
var_dump(Ascon::mac($key, 'Testmessage'));

0 comments on commit 902a803

Please sign in to comment.