Used to encrypt and decrypt credentials on the go!
npm install encrypt-decrypt-cryptobash
npm install encrypt-decrypt-crypto
``2. To Create a Secret key
a. Create a new file to create the secret key
b. Import the current package
const credentialHelper = require('encrypt-decrypt-crypto');
c. Add a call to create a secret key - mostly used one time or when the secret key needs to be changed
const secretKey = await credentialHelper.createSecretKey();
console.log("Secret Key: " + secretKey);
d. Run the file to create the Secret key, sample command below
node script.js
3. Encrypt a plain text password
a. Create a new file for encryption OR reuse the above file created for secret key
b. Import the current package
const credentialHelper = require('encrypt-decrypt-crypto');
c. Add a call to encrypt the password - mostly used one time or when the plain text password is changed. The return value is an array where the first value is the Encrypted text and the second value is the IV.
const encryptedText = await credentialHelper.encryptText("plainTextPassword", secretKey);
console.log("Encrypted Text is: " + encryptedText[0] + ", IV: " + encryptedText[1]);
d. Run the file to encrypt the Plain text password, sample command below:
node script.js
4. Decrypted the encrypted password
a. Import the current package in the file where the decryption of the password is needed.
const credentialHelper = require('encrypt-decrypt-crypto');
b. Add a call to decrypt the password and pass the encrypted text, IV and the secret key.
const decryptedText = await credentialHelper.decryptText(encryptedText, IV, secretKey);
console.log("Decrypted Plain password: " + decryptedText);
Note: The createSecretKey, encryptText and decryptText are async functions, so please add the calls to these in an async function or an async block. Sample below:
(async () => {
---- code here
})();