0.1.0 • Published 1 year ago

@repoxcode/secret v0.1.0

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
1 year ago

Secret

Dynamic and easy to use secret generator library.

Get Started

To get started, simply add the package to your project using the following command:

# using npm
npm install @repoxcode/secret

# using yarn
yarn add @repoxcode/secret

Encrypt and Decrypt

Usage Example

import Secret from "secret";

// encrypt message
const encrypted = Secret.encrypt("secret message", { secret: "secretKey", secretIV: "anotherSecretKey" });

// decrypt message
const decrypted = Secret.decrypt("ENCRYPTED_SECRET", { secret: "secretKey", secretIV: "anotherSecretKey" });

You can make this easier by placing the secret key and secret key IV in environment variables

ENCRYPT_SECRET="secretKey"
ENCRYPT_SECRET_IV="anotherSecretKey"

After you add the environment variable as above, you can directly use the function more easily.

import Secret from "secret";

// encrypt message
const encrypted = Secret.encrypt("secret message");

// decrypt message
const decrypted = Secret.decrypt("ENCRYPTED_SECRET");

Encrypt

encrypt(data, {secret, secretIV});
ParametersTypeDefaultRequired
datastringtrue
secretstringtrue
secretIVstringtrue

Decrypt

decrypt(data, {secret, secretIV});
ParametersTypeDefaultRequired
datastringtrue
secretstringtrue
secretIVstringtrue

Encode and Decode

Usage Example

import Secret from "secret";

// encode message
const encoded = Secret.encode("secret message");

// decode message
const decoded = Secret.decode("secret message");

Encode

encode(data, type);
ParametersTypeDefaultRequired
datastringtrue
typeEnum ascii, base64, base64url, binary, hex, latin1, ucs2, ucs-2, utf16le, utf-16le, utf8, utf-8base64urltrue

Decode

decode(data, type);
ParametersTypeDefaultRequired
datastringtrue
typeEnum ascii, base64, base64url, binary, hex, latin1, ucs2, ucs-2, utf16le, utf-16le, utf8, utf-8base64urltrue

Scrypt

Usage Example

import Secret from "secret";

// hash message
const hashed = Secret.scrypt("secret message", { salt: "salt"});

// compare hashed message
const compareResult = Secret.scryptCompare("secret message", "HASHED_SECRET", { salt: "salt"});

You can make this easier by placing the salt in environment variables

SCRYPT_SALT="salt"

After you add the environment variable as above, you can directly use the function more easily.

import Secret from "secret";

// hash message
const hashed = Secret.scrypt("secret message");

// compare hashed message
const compareResult = Secret.scryptCompare("secret message", "HASHED_SECRET");

scrypt

scrypt(data, {salt, type});
ParametersTypeDefaultRequired
datastringtrue
saltstringfalse
typeEnum: hex, base64, base64urlbase64urlfalse

scrypt compare

If you define a type when encrypting, then when comparing, you must also define the same type.

scrypt(data, hash, {salt, type});
ParametersTypeDefaultRequired
datastringtrue
hashstringtrue
saltstringfalse
typeEnum: hex, base64, base64urlbase64urlfalse

Scrypt Auto

Usage Example

import Secret from "secret";

// hash message
const hashed = Secret.scryptAuto("secret message");

// compare hashed message
const compareResult = Secret.scryptAutoCompare("secret message", "HASHED_SECRET");

You can make this easier by placing the salt in environment variables

SCRYPT_SALT="salt"

After you add the environment variable as above, you can directly use the function more easily.

import Secret from "secret";

// hash message
const hashed = Secret.scryptAuto("secret message");

// compare hashed message
const compareResult = Secret.scryptAutoCompare("secret message", "HASHED_SECRET");

scrypt auto

scrypt(data, {salt, type});
ParametersTypeDefaultRequired
datastringtrue
saltstringfalse
typeEnum: hex, base64, base64urlbase64urlfalse

scrypt auto compare

If you define a type when encrypting, when comparing, you do not have to define the same type

scrypt(data, hash, {salt, type});
ParametersTypeDefaultRequired
datastringtrue
hashstringtrue
saltstringfalse
typeEnum: hex, base64, base64urlbase64urlfalse
0.1.0

1 year ago