
Security News
Open Source CAI Framework Handles Pen Testing Tasks up to 3,600× Faster Than Humans
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
encrypt-string
Advanced tools
Encrypt and decrypt a string using another string (or an `Uint8Array`) as password
Encrypt and decrypt a string using another string (or an
Uint8Array
) as password
$ npm install encrypt-string
const { encryptString, decryptString } = require('encrypt-string');
(async () => {
const secret = 'This is the secret';
const password = 'P4s$w0Rd!';
const encrypted = await encryptString(secret, password);
console.log(encrypted);
//=> !!(AP#M4i]$9<c0,iw4;%a4/C%*@EB0jp'+$$pww]yLPd3[G'2/eS`@_u/[@.dfF#$9]Xl2:o:@FkoOA'@jq}=`f$W!>gbX1L678@ghM`.=7V(K:db]M5i{u5[ga~CojWx'M_e7;#~lD-aVDs-D_o)+e16d:-`Dz!bVJ3
const decrypted = await decryptString(encrypted, password);
console.log(decrypted);
//=> 'This is the secret'
await decryptString(encrypted, 'wrong-password');
//=> DecryptionError: Unable to decrypt - password is incorrect or data is corrupted.
})();
Note: it seems Themis uses some cryptographically secure random bytes in the encryption process, therefore the encryption result is different on each run, even for the same secret and same password. If you run the example above, you will probably get a different encrypted string.
Don't worry, all of them are valid and all of them can be decrypted successfully. You can see this by decrypting the output I received directly:
const { decryptString } = require('encrypt-string');
(async () => {
const encrypted = '!!(AP#M4i]$9<c0,iw4;%a4/C%*@EB0jp\'+$$pww]yLPd3[G\'2/eS`@_u/[@.dfF#$9]Xl2:o:@FkoOA\'@jq}=`f$W!>gbX1L678@ghM`.=7V(K:db]M5i{u5[ga~CojWx\'M_e7;#~lD-aVDs-D_o)+e16d:-`Dz!bVJ3';
const password = 'P4s$w0Rd!';
const decrypted = await decryptString(encrypted, password);
console.log(decrypted);
//=> 'This is the secret'
})();
Async function that encrypts data
with password
. Returns an encrypted string, composed only of printable ASCII characters. More precisely, it uses all 94 printable ASCII characters (excluding space).
The output can be different for multiple executions with the same parameters, but all of them will be valid (and they will always have at least the same length).
Type: string
The string to be encrypted.
Type: string | Uint8Array
The string (or Uint8Array
) to be used as password.
Async function that decrypts encryptedData
with password
. Returns the original string.
If encryptedData
is not valid or the password is incorrect, this function will throw a DecryptionError
.
Type: string
The data to be decrypted.
Type: string | Uint8Array
The string (or Uint8Array
) to be used as password.
When you encrypt a string, the length of the encrypted result will be equal to 125% of the original length, plus 140 characters.
Uint8Array
using another Uint8Array
as passwordFAQs
Encrypt and decrypt a string using another string (or an `Uint8Array`) as password
We found that encrypt-string demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CAI is a new open source AI framework that automates penetration testing tasks like scanning and exploitation up to 3,600× faster than humans.
Security News
Deno 2.4 brings back bundling, improves dependency updates and telemetry, and makes the runtime more practical for real-world JavaScript projects.
Security News
CVEForecast.org uses machine learning to project a record-breaking surge in vulnerability disclosures in 2025.