DholeCrypto.js
JavaScript port of Dhole Cryptography (PHP).
Libsodium wrapper for Soatok's JavaScript projects. Released under the very permissive ISC license.
Important: Until version
v1.0.0
is released, please don't deploy this library in any production systems. I'll tagv1.0.0
when I'm confident in the correctness and security of the implementation.
Installation
npm install dhole-crypto
Usage
Asymmetric Cryptography
Digital Signatures
const Asymmetric AsymmetricSecretKey} = ; { let wolfSecret = await AsymmetricSecretKey; let wolfPublic = wolfSecret; let message = "Your $350 awoo fine has been paid UwU"; let signature = await Asymmetric; if !await Asymmetric console; };
Authenticated Public-Key Encryption
const Asymmetric AsymmetricSecretKey} = ; { let foxSecret = await AsymmetricSecretKey; let foxPublic = foxSecret; let wolfSecret = await AsymmetricSecretKey; let wolfPublic = wolfSecret; let message = "Encrypt me UwU"; let encrypted = await Asymmetric; let decrypted = await Asymmetric; console; // "Encrypt me UwU"};
Anonymous Public-Key Encryption
const Asymmetric AsymmetricSecretKey} = ; { let foxSecret = await AsymmetricSecretKey; let foxPublic = foxSecret; let message = "Encrypt me UwU"; let encrypted = await Asymmetric; let decrypted = await Asymmetric; console; // "Encrypt me UwU"};
Symmetric Cryptography
Encryption
const Symmetric SymmetricKey } = ; {let symmetricKey = await SymmetricKey; let message = "Encrypt me UwU";let encrypted = await Symmetric;let decrypted = await Symmetric;console; // "Encrypt me UwU"};
Encryption with Additional Data
const Symmetric SymmetricKey } = ; { let symmetricKey = await SymmetricKey; let message = "Encrypt me UwU"; let publicData = "OwO? UwU"; let encrypted = await Symmetric; let decrypted = await Symmetric; console; // "Encrypt me UwU"};
Unencrypted Message Authentication
const Symmetric SymmetricKey } = ; { let symmetricKey = await SymmetricKey; let message = "AWOOOOOOOOOOOO"; let mac = await Symmetric; if !await Symmetric console; };
Password Storage
const Password SymmetricKey } = ; { let symmetricKey = await SymmetricKey; let pwHandler = symmetricKey; let password = 'cowwect howse battewy staple UwU'; let pwhash = await pwHandlerhashpassword; if !await pwHandler console; };
Keyring
You can serialize any key by using the Keyring
class.
const AsymmetricSecretKey Keyring SymmetricKey } = ; { let foxSecret = await AsymmetricSecretKey; let foxPublic = foxSecret; let symmetric = await SymmetricKey; // Load a serializer let ring = ; // Serialize to string let sk = await ring; let pk = await ring; let key = await ring; // Load from string let loadSk = await ring; let loadPk = await ring; let loadSym = await ring;};
The Keyring
class also supports keywrap. Simply pass a separate SymmetricKey
instance to the constructor to get wrapped keys.
const AsymmetricSecretKey Keyring SymmetricKey } = ; { // Keywrap key... let wrap = await SymemtricKey; let foxSecret = await AsymmetricSecretKey; let foxPublic = foxSecret; let symmetric = await SymmetricKey; // Load a serializer let ring = wrap; // Serialize to string let sk = await ring; let pk = await ring; let key = await ring; // Load from string let loadSk = await ring; let loadPk = await ring; let loadSym = await ring;};
Support
If you run into any trouble using this library, or something breaks, feel free to file a Github issue.
If you need help with integration, Soatok is available for freelance work.