
Product
Introducing Socket Firewall Enterprise: Flexible, Configurable Protection for Modern Package Ecosystems
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.
@emartech/easy-crypto
Advanced tools
Provides simple wrappers around Node's crypto implementation. The library provides two interfaces: simple and advanced. Simple mode is designed for ease-of-use and advanced mode provides some performance benefits in certain use-cases. See below for more details.
All the underlying crypto operations are the same.
To get started just require the lib and create an instance right away.
const crypto = require('crypto');
const easyCrypto = require('@emartech/easy-crypto');
const password = crypto.randomBytes(24).toString('hex');
const randomData = crypto.randomBytes(1024).toString('hex');
const ecrypto = easyCrypto(password);
async function exampleAsyncFunction() {
const encrypted = await ecrypto.encrypt(randomData);
const decrypted = await ecrypto.decrypt(encrypted);
randomData === decrypted; //true
}
Key derivation is a resource heavy process. The default settings recompute the key before each encryption/decryption process.
These options allow you to cache the result of the key derivation. This is required if you need to encrypt/decrypt multiple times with the same derived key. Caching the keys with node-cache saves you the time to have to recompute it before every encryption/decryption.
To get started just require the lib and create an instance right away.
const crypto = require('crypto');
const easyCrypto = require('@emartech/easy-crypto');
const password = crypto.randomBytes(24).toString('hex');
const randomData = [
crypto.randomBytes(1024).toString('hex'),
crypto.randomBytes(1024).toString('hex'),
crypto.randomBytes(1024).toString('hex')
];
const ecrypto = easyCrypto(password, {
encryptCacheTtl: 3600,
decryptCachePoolSize: 100,
});
async function exampleAsyncFunction() {
const encrypted = await Promise.all(
randomData.map(item => ecrypto.encrypt(item))
);
const decrypted = await Promise.all(
encrypted.map(item => ecrypto.decrypt(item))
);
return data.reduce((allValid, item, index) => {
return allValid && item === decrypted[index];
}, true);
}
There aren't too many options you can change and that is on purpose. This small wrapper library is secure by default. You can change two configurations: encryptCacheTtl, decryptCachePoolSize by passing them to the initialization function as follows:
let ecrypto = require('@emartech/easy-crypto')('password', {
encryptCacheTtl: 3600,
decryptCachePoolSize: 100,
});
passwordpassword should be any normal string. It will be used to generate the encryption key.
encryptCacheTtlTime in seconds while the same key is reused during encryption. Must be an integer.
decryptCachePoolSizeMaximum number of keys kept in the cache during decryption. Must be an integer.
plaintext) -> ciphertextplaintext must be utf-8 encoded string. It will be "converted" to bytes and those will be used for the cryptographic operations. The output of this operations is base64 encoded buffers. This will be used as the input of the decrypt operation. This return value is a Promise.
ciphertext) -> plaintextciphertext must be the output of the encrypt method. The library is not compatible with any other encryption library out of the box! The output of this operation is the original utf-8 encoded string. This return value is a Promise.
The library is only a thin wrapper of node's own crypto module. It uses well known and battle tested encryption techniques. It provides a convenient wrapper around these functions, taking away the details of using encryption correctly. Feel free to explore the source!
passwordSaltSize random bytes are used to create the 256 bit long encryption key from the password using pbkdf2 and the given iteration countplaintext is encrypted using aes-256-gcm with the generated key and a 12 bytes long random initialization vector, this operation also yields a 16 bytes long authentication tag, which can be used to verify the encrypted data's integritypasswordSalt bytes, initialization vector bytes, ciphertext bytes, authentication tag bytesbase64 and returns itbase64 input to bytespasswordSalt bytes, initialization vector bytes, ciphertext bytes, authentication tag bytespasswordSalt bytes and the password are used to generate the 256 bit long encryption key using pbkdf2 and the given iteration countciphertext bytes are decrypted using aes-256-gcm with the generated key the initialization vector bytes. During encryption the integrity of the date is also verified using the authentication tag bytesutf-8 and returns itPlease find us, we would love your feedback!
FAQs
Provides simple wrappers around Node's crypto implementation.
The npm package @emartech/easy-crypto receives a total of 1,026 weekly downloads. As such, @emartech/easy-crypto popularity was classified as popular.
We found that @emartech/easy-crypto demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 153 open source maintainers 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.

Product
Socket Firewall Enterprise is now available with flexible deployment, configurable policies, and expanded language support.

Security News
Open source dashboard CNAPulse tracks CVE Numbering Authorities’ publishing activity, highlighting trends and transparency across the CVE ecosystem.

Product
Detect malware, unsafe data flows, and license issues in GitHub Actions with Socket’s new workflow scanning support.