-
Notifications
You must be signed in to change notification settings - Fork 0
Examples
Include the script file:
Botan.mjs || Botan.tis
The binding library API offers:
- Hashing (SHA-256, MD5...)
- Password Hashing (Argon2, Bcrypt)
- Encoding & Decoding (Base64, Hex)
- Encrypting & Decrypting (AES, Twofish...)
- Other Utilities
! The API is very data sensitive, invalid data may lead to crash
Hash a string using given method https://botan.randombit.net/handbook/api_ref/hash.html
Code:
Botan.hash("SHA-256", "data")
Return: "3A6EB0790F39AC87C94F3856B2DD2C5D110E6811602261A9A923D3BB23ADC8B7"
Generate password hashing using methods [argon, bcrypt] https://botan.randombit.net/handbook/api_ref/passhash.html
Generate Methods : argon, bcrypt
await Botan.password("bcrypt", "data")
Return: "$2a$12$dlkARcTc2dBCQjWb5tXIYOi0TtjXEzcFbPUDL.CqmOkpOmL3KXp5e"
! Each time you call this code even with the same data, the returned value will be different, Therefore you need a checker function
Check Methods : check-argon, check-bcrypt
await Botan.password("check-bcrypt", "data", "$2a$12$dlkARcTc2dBCQjWb5tXIYOi0TtjXEzcFbPUDL.CqmOkpOmL3KXp5e")
Return: true
Methods : base64, hex
Encode
Botan.encode("base64", "data");
Return: "ZGF0YQ=="
Decode
Botan.decode("base64", "ZGF0YQ==");
Return: "data"
Encrypt
- Key must be of specified length per method requirement, you should hash it.
- If IV(nonce) is provided it will be used to encrypt the data, otherwise a new one is generated.
var crypto = await Botan.cipher("AES-256/CBC", "data", Botan.hash("SHA-256", "key"));
crypto.data
// Return: "6B3EBE861F24420F7FD5DCC4CF7CB0F3"
crypto.iv
// Return: "C5B8CF8DFC4647318A65271DFE39CF52"
// randomly generated, you can provide an IV as 4th argument.
Return: Object with data and iv
Decrypt
- Key must be of specified length per method requirement, you should hash it.
- IV(nonce) must be provided
// The same values returned from the previous sample now will be decrypted.
var crypto = await Botan.decipher("AES-256/CBC", "6B3EBE861F24420F7FD5DCC4CF7CB0F3",
Botan.hash("SHA-256", "key"), "C5B8CF8DFC4647318A65271DFE39CF52");
crypto.data
// Return: "data"
crypto.iv
// Return: "C5B8CF8DFC4647318A65271DFE39CF52"
Return: Object with data and iv
method : https://botan.randombit.net/handbook/api_ref/block_cipher.html
Botan.iv("AES-256/CBC")
Return: "C3C2DCFF84452487DF929C5DB3E66FDF" - randomly generated per method requirement.