1.0.0 • Published 3 years ago

abrupt-crypto v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

abrupt-rand is a derivative of the entire packge abrupt https://www.npmjs.com/package/abrupt

Crypto

const crypto = require("abrupt-crypto")
const { base64, md5, sha256, AES, morse, rot } = crypto

// Base64
const base64_encoded = base64.encode("Hello World!")
base64_encoded // SGVsbG8gV29ybGQh
const base64_decoded = base64.decode(base64_encoded)
base64_decoded // Hello World!

// Hash
md5("Hello World!") // ed076287532e86365e841e92bfc50d8c
md5("Hello World!", "base64") // 7Qdih1MuhjZehB6Sv8UNjA==
sha256("Hello World!") // 7f83b1657ff1fc53b92dc18148a1d65dfc2d4b1fa3d677284addd200126d9069
sha256("Hello World!", "base64") // f4OxZX/x/FO5LcGBSKHWXfwtSx+j1ncoSt3SABJtkGk=

// AES 256 CBC:

// AES: Base64 (default)
const data = AES.encode("Hello World!", "key")
const [ encoded ] = data // WtbLPEWi4eu+r4bFYQR63w==
const decoded = AES.decode(...data, "key")
decoded // Hello World!

// AES: Hex
const data = AES.encode("Hello World!", "key", "hex")
const [ encoded ] = data // a7bda69f5eaa9d208b370df02c24e606
const decoded = AES.decode(...data, "key")
decoded // Hello World!

// Morse
const morse_encoded = morse.encode("Hello World!")
morse_encoded // .... . .-.. .-.. ---  / .-- --- .-. .-.. -.. -.-.--
const morse_decoded = morse.decode(morse_encoded)
morse_decoded // hello world!

// Rot
rot("Hello World!")// (Uryyb Jbeyq!) ROT 13 
rot("Hello World!", 10) // (Rovvy Gybvn!) ROT 10