@aljeerz/lets-secure
v0.0.2
Published
Utility Factory for NodeJS Crypto, OTPLib ...
Downloads
6
Readme
@aljeerz/lets-secure
This Repository Provides Utility Factory for NodeJS Native Crypto, OTPLib
Features
Head to OTPLib for more details.
⚠️ PS: HMAC OTP Not Implemented Yet
Installation
npm install @aljeerz/lets-secure otplib @otplib/core
Usage
- Initialisation
/******** Example Initialisation Data ********/
const totpSecret = "secureSecret";
const secret = crypto.randomBytes(32);
const cipher = crypto.createCipheriv("aes-256-cbc", secret, iv);
const decipher = crypto.createDecipheriv("aes-256-cbc", secret, iv);
/*********************************************/
// Declare In Constructor
const factory = new LetsSecureFactory(
[
{
name: "testone",
cipher,
decipher,
},
],
[
{
name: "testoneOTP",
size: 4,
type: "rand",
},
{
name: "testoneTOTP",
size: 8,
type: "totp",
secret: totpSecret,
},
]
);
// Add Aditional Declarations On
factory.ciphDeclare("newCipher", newCipher, newCecipher);
const ret = factory.otpDeclare("newOTP", 4, "rand");
const ret = factory.otpDeclare("newTOTP", 6, "totp", totpSecret);
- Encrypt String
const myEncryptedStr = factory.cipherStr("newCipher", myString, "utf-8", "base64");
const myDecrptedStr = factory.decipherStr("newCipher", myEncryptedStr, "base64", "utf-8");
- Generate Random OTP
const OTPCode = factory.otpGenerate("newOTP");
- Generate Time Based OTP (TOTP)
const TOTPCode = factory.otpGenerate("newTOTP");