safez-CryptX is a versatile encryption and decryption library designed for both Node.js and browser environments. It supports various encryption modes, allowing developers to encrypt entire objects, specific fields within objects, or simple values. This document provides a comprehensive guide on how to integrate and use safez-CryptX in your projects.
Add safez-cryptx to your project using the following command:
npm install @safez/safez-cryptx
# or
yarn add @safez/safez-cryptx
To use safez-CryptX, import it into your project and configure it with your encryption settings. This setup will automatically encrypt and decrypt data based on the specified configurations.
const { encryptValue, decryptValue } = require('@safez/safez-cryptx');
import * as cryptx from '@safez/safez-cryptx';
Encrypt and decrypt values simply and effectively with safez-CryptX.
let encrypted = encryptValue('Hello World!', 'dummysecretkey');
console.log(encrypted); // Encrypted data
let decrypted = decryptValue(encrypted, 'dummysecretkey');
console.log(decrypted); // Hello World!
Manage encryption and decryption of entire objects or specific fields within objects.
const data = {
name: 'SafeZ',
type: 'security'
};
const encrypted = cryptx.encryptData(data, 'dummykey', 'full');
const decrypted = cryptx.decryptData(encrypted, 'dummykey', 'full');
console.log(encrypted); // Encrypted string
console.log(decrypted); // {name: "SafeZ", type: "security"}
const data = {
name: 'SafeZ',
type: 'security'
};
const encrypted = cryptx.encryptData(data, 'dummykey', 'field');
const decrypted = cryptx.decryptData(encrypted, 'dummykey', 'field');
console.log(encrypted); // {name: "encrypted string", type: "encrypted string"}
console.log(decrypted); // {name: "SafeZ", type: "security"}
- Encryption Secret Management: Keep your encryption secret key secure and avoid exposing it in client-side code.
- Optimize Encryption Use: Use encryption selectively, balancing security needs with performance.
- Usage Failures: Check that the package is installed, secret key is correctly configured.
- Can safez-CryptX be used in any web application? Yes, it's designed to be compatible across both Node.js and browser environments.