krypton
A very light weight package written in Typescript combining node/crypto
and bcrypt
for some helpful methods.
NOTE, I am not using my own crypto with this project, it is using recommend crypto from node and bcrypt.
Import
Import what you need. You will most likely not need to import all of these.
import {
KrBcrypt,
KrHash,
KrHashAlgorithm,
KrRSA,
KrRSAKeyPair
} from "element-ts/krypton";
Examples
KrBcrypt
const password: string = "1234";
const createdPassword: Buffer = await KrBcrypt.createPassword(password);
const checkPassword: boolean = await KrBcrypt.verifyPassword(password, createdPassword);
KrHash
const hashedData: Buffer = KrHash.hash(Buffer.from("Hello, world!");
const hashedData: Buffer = KrHash.hash(Buffer.from("Hello, world!", KrHashAlgorithm.sha512));
const hasher: KrHash = new KrHash()
hasher.append(Buffer.from("Hello"));
hasher.append(Buffer.from("World"));
const hashedData: Buffer = hasher.hash();
KrRSA
const keys: KrRSAKeyPair = KrRSA.generateKeys();
const message: string = "Hello, world!";
const dataUnEncrypted: Buffer = Buffer.from(message);
const dataEncrypted: Buffer = KrRSA.encrypt(dataUnEncrypted, keys.publicKey);
const dataDecrypted: Buffer = KrRSA.decrypt(dataEncrypted, keys.privateKey);
const messageDecrypted: string = dataDecrypted.toString("utf8");
Documentation
You can view the
declaration files or even the
source code on GitHub.
Bugs
If you find any bugs please create an issue on GitHub or if you are old
fashioned email me at elijah@elijahcobb.com.