Skip to content
JavaScript implementation of dhole-cryptography
Branch: master
Clone or download
Latest commit c4e42ce Apr 23, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Boyscouting Apr 21, 2019
test Key management Apr 16, 2019
.gitignore Initial commit Apr 13, 2019
.travis.yml We want version 11, not version 7 Apr 13, 2019
LICENSE.txt Initial commit Apr 13, 2019
README.md Add Patreon badge Apr 23, 2019
index.js Add index.js file for importing dholecrypto-js into other projects Apr 14, 2019
package-lock.json Key management Apr 16, 2019
package.json Key management Apr 16, 2019

README.md

DholeCrypto.js

Support on Patreon Travis CI npm version

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 tag v1.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
} = require('dhole-crypto');

let wolfSecret = AsymmetricSecretKey.generate();
let wolfPublic = wolfSecret.getPublicKey();

let message = "Your $350 awoo fine has been paid UwU";

let signature = Asymmetric.sign(message, wolfSecret);

if (!Asymmetric.verify(message, wolfPublic, signature)) {
    console.log("Invalid signature. Awoo not authorized.");
}

Authenticated Public-Key Encryption

const { 
    Asymmetric, 
    AsymmetricSecretKey
} = require('dhole-crypto');

let foxSecret = AsymmetricSecretKey.generate();
let foxPublic = foxSecret.getPublicKey();

let wolfSecret = AsymmetricSecretKey.generate();
let wolfPublic = wolfSecret.getPublicKey();

let message = "Encrypt me UwU";
let encrypted = Asymmetric.encrypt(message, foxPublic, wolfSecret);
let decrypted = Asymmetric.decrypt(encrypted, foxSecret, wolfPublic);
console.log(decrypted); // "Encrypt me UwU"

Anonymous Public-Key Encryption

const { 
    Asymmetric, 
    AsymmetricSecretKey
} = require('dhole-crypto');

let foxSecret = AsymmetricSecretKey.generate();
let foxPublic = foxSecret.getPublicKey();

let message = "Encrypt me UwU";
let encrypted = Asymmetric.seal(message, foxPublic);
let decrypted = Asymmetric.unseal(encrypted, foxSecret);
console.log(decrypted); // "Encrypt me UwU"

Symmetric Cryptography

Encryption

const {
    Symmetric,
    SymmetricKey
} = require('dhole-crypto');

let symmetricKey = SymmetricKey.generate();

let message = "Encrypt me UwU";
let encrypted = Symmetric.encrypt(message, symmetricKey);
let decrypted = Symmetric.decrypt(encrypted, symmetricKey);
console.log(decrypted); // "Encrypt me UwU"

Encryption with Additional Data

const {
    Symmetric,
    SymmetricKey
} = require('dhole-crypto');

let symmetricKey = SymmetricKey.generate();

let message = "Encrypt me UwU";
let publicData = "OwO? UwU";
let encrypted = Symmetric.encryptWithAd(message, symmetricKey, publicData);
let decrypted = Symmetric.decryptWithAd(encrypted, symmetricKey, publicData);
console.log(decrypted); // "Encrypt me UwU"

Unencrypted Message Authentication

const {
    Symmetric,
    SymmetricKey
} = require('dhole-crypto');

let symmetricKey = SymmetricKey.generate();

let message = "AWOOOOOOOOOOOO";
let mac = Symmetric.auth(message, symmetricKey);
if (!Symmetric.verify(message, mac, symmetricKey)) {
    console.log("Unauthorized Awoo. $350 fine incoming");
}

Password Storage

const {
    Password,
    SymmetricKey
} = require('dhole-crypto');

let symmetricKey = SymmetricKey.generate();
let pwHandler = new Password(symmetricKey);

let password = 'cowwect howse battewy staple UwU';
let pwhash = pwHandler.hash(password);
if (!pwHandler.verify(password, pwhash)) {
    console.log("access denied");    
}

Keyring

You can serialize any key by using the Keyring class.

const {
    AsymmetricSecretKey,
    Keyring,
    SymmetricKey
} = require('dhole-crypto');

let foxSecret = AsymmetricSecretKey.generate();
let foxPublic = foxSecret.getPublicKey();
let symmetric = SymmetricKey.generate();
// Load a serializer
let ring = new Keyring();

// Serialize to string
let sk = ring.save(foxSecret);
let pk = ring.save(foxPublic);
let key = ring.save(symmetric);

// Load from string
let loadSk = ring.load(sk);
let loadPk = ring.load(pk);
let loadSym = ring.load(key);

The Keyring class also supports keywrap. Simply pass a separate SymmetricKey instance to the constructor to get wrapped keys.

const {
    AsymmetricSecretKey,
    Keyring,
    SymmetricKey
} = require('dhole-crypto');

// Keywrap key...
let wrap = SymemtricKey.generate();

let foxSecret = AsymmetricSecretKey.generate();
let foxPublic = foxSecret.getPublicKey();
let symmetric = SymmetricKey.generate();

// Load a serializer
let ring = new Keyring(wrap);

// Serialize to string
let sk = ring.save(foxSecret);
let pk = ring.save(foxPublic);
let key = ring.save(symmetric);

// Load from string
let loadSk = ring.load(sk);
let loadPk = ring.load(pk);
let loadSym = ring.load(key);

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.

You can’t perform that action at this time.