-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
eeb6599
commit b31b5fe
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// depending on your environment, include JsAscon as module, script tag or require from nodejs | ||
//const JsAscon = require('js-ascon') // when using as installed npm module | ||
const JsAscon = require('../dist/ascon') | ||
|
||
// test convenient methods | ||
let key = 'mypassword' | ||
let message = ['this can be any data type 😎 文', 123] | ||
let associatedData = 'Some data 😋 文 This data is not contained in the encrypt output. You must pass the same data to encrypt and decrypt in order to be able to decrypt the message.' | ||
let encrypted = JsAscon.encryptToHex(key, message, associatedData) | ||
let decrypted = JsAscon.decryptFromHex(key, encrypted, associatedData) | ||
JsAscon.assertSame(JSON.stringify(message), JSON.stringify(decrypted), 'Encryption/Decryption to hex failed') | ||
|
||
console.log('convienient-usage.js successfully done') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// depending on your environment, include JsAscon as module, script tag or require from nodejs | ||
//const JsAscon = require('js-ascon') // when using as installed npm module | ||
const JsAscon = require('../dist/ascon') | ||
|
||
// key must be 16 bytes or 20 bytes, depending on variant | ||
const 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 | ||
const nonce = JsAscon.getRandomUintArray(16) | ||
// this is the text you want to encrypt | ||
const plaintext = 'Hi, i am a secret message!' | ||
// 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 | ||
const associatedData = 'Some data to pass to encryption and decryption - This data is not contained in the ciphertext output.' | ||
const ciphertextByteArray = JsAscon.encrypt(key, nonce, associatedData, plaintext) | ||
const plaintextDecrypted = JsAscon.decrypt(key, nonce, associatedData, ciphertextByteArray) | ||
|
||
console.log("Hash") | ||
console.log(JsAscon.hash("Testmessage")) | ||
|
||
console.log("Mac") | ||
console.log(JsAscon.mac(key, "Testmessage")) | ||
|
||
console.log('raw-usage.js successfully done') |