A high-performance encryption, token generation, and string manipulation library built by the Zexson Team, featuring advanced security, customizable algorithms, and high-entropy randomness.
-
🔐 Secure Encryption & Decryption
- Custom encryption algorithm with dynamic random padding
- Base64 encoding with character shifting for added security
- Key-based encryption for controlled access
-
🔑 Token Generation
- Flexible token creation with customizable length and character sets
- Multiple predefined character sets for various use cases
- High-entropy random generation for strong security
-
📝 Advanced String Comparison
- Supports both case-sensitive and case-insensitive comparison
- Secure comparison of encrypted strings
- Detailed result analysis for accurate matching
Install the package via npm:
npm install zexson_toolkit
import { cryptExample } from 'zexson_toolkit'
cryptExample('zexson_toolkit','zexson_team')
import { encrypt, decrypt } from 'zexson_toolkit'
// Basic encryption
const encrypted = encrypt("sensitive data")
const decrypted = decrypt(encrypted)
import { encrypt } from 'zexson_toolkit'
// Custom encryption with options
const encrypted = encrypt("sensitive data", {
key: 'customKey'
})
import { tokenGenerator } from 'zexson_toolkit'
// Generate a token with specified length and character set
const token = tokenGenerator(16, 'defaultSet')
import { isEqual } from 'zexson_toolkit'
// Compare strings with options
const result = isEqual("text1", "text2", {
caseSensitive: false,
key: "customKey",
log: true
})
import { base64Encode, base64Decode } from 'zexson_toolkit'
// Encode a string
const encoded = base64Encode("example string", "customKey")
// Decode a string
const decoded = base64Decode(encoded, "customKey")
import { encryptObject, decryptObject } from 'zexson_toolkit'
// Encrypt an object
const data = { username: "JohnDoe", password: "12345" }
const encryptedData = encryptObject(data, "my-secret-key")
// Decrypt an object
const decryptedData = decryptObject(encryptedData, "my-secret-key")
import { encryptBody, decryptBody } from 'zexson_toolkit'
// Encrypt an object with the encryptBody function
const data = { username: "JohnDoe", password: "12345" }
const encryptedData = encryptBody(data, "my-secret-key")
// Decrypt the object with the decryptBody function
const decryptedData = decryptBody(encryptedData, "my-secret-key")
// Advanced encryption with complex data structure
const complexData = {
username: "JohnDoe",
password: "12345",
about: { gender: 'male', age: 12 },
hobbies: ['football', 'basketball', { football: true, basketball: false }]
}
const encryptedComplexData = encryptBody(complexData, "my-secret-key")
const decryptedComplexData = decryptBody(encryptedComplexData, "my-secret-key")
The isEquals
function deeply compares two objects or arrays for equality, with optional type checking and schema validation.
import { isEquals } from 'zexson_toolkit'
const obj1 = { name: "John", age: 30 }
const obj2 = { name: "John", age: 30 }
console.log(isEquals(obj1, obj2)) // true
import { isEquals } from 'zexson_toolkit'
const obj1 = { name: "John", details: { city: "New York", zip: 10001 } }
const obj2 = { name: "John", details: { city: "New York", zip: 10001 } }
console.log(isEquals(obj1, obj2)) // true
import { isEquals } from 'zexson_toolkit'
const obj1 = { name: "John", age: 25 }
const obj2 = { name: "Jane", age: 30 }
console.log(isEquals(obj1, obj2, { checkType: true })) // true
import { isEquals } from 'zexson_toolkit'
const arr1 = [1, 2, 3, 4]
const arr2 = [1, 2, 3, 4]
console.log(isEquals(arr1, arr2)) // true
import { isEquals } from 'zexson_toolkit'
const obj1 = {
name: "Alice",
age: 28,
hobbies: ["reading", "gaming"],
address: { city: "Paris", zip: 75000 }
}
const obj2 = {
name: "Alice",
age: 28,
hobbies: ["reading", "gaming"],
address: { city: "Paris", zip: 75000 }
}
console.log(isEquals(obj1, obj2)) // true
import { isEquals } from 'zexson_toolkit'
const obj1 = { name: "John", age: 30 }
const obj2 = { name: "John", age: 30, gender: "male" }
console.log(isEquals(obj1, obj2)) // false
The isEquals
function now supports schema validation for strict structural comparisons.
import { isEquals, encryptObject, decryptObject } from 'zexson_toolkit'
const schema = {
name: 'string',
age: 'number',
status: { type: 'string', enum: ['active', 'inactive'] },
hobbies: {
type: 'array',
items: { type: 'string', enum: ['reading', 'gaming', 'sports'] }
},
address: {
type: 'object',
properties: {
city: 'string',
zip: 'number'
}
}
};
const obj1 = {
name: "Alice",
age: 28,
status: "active",
hobbies: [],
address: { city: "Paris", zip: 75000 }
};
const eObj1 = encryptObject(obj1);
const obj2 = {
name: "Bob",
age: 30,
status: "inactive",
hobbies: ["reading", "gaming", "sports"],
address: { city: "London", zip: 12345 }
};
const eObj2 = encryptObject(obj2);
console.log(isEquals(obj1, obj2, { checkType: true, schema })) // true
console.log(decryptObject(eObj1), decryptObject(eObj2))
import { isEquals } from 'zexson_toolkit'
const schema: SchemaType = {
name: 'string',
age: 'number',
status: { type: 'string', enum: ['active', 'inactive'] },
hobbies: {
type: 'array',
items: { type: 'string', enum: ['reading', 'gaming', 'sports'] }
}
}
const obj1 = {
name: 'John',
age: 30,
status: 'inactive',
hobbies: ['gaming']
};
const obj2 = {
name: 'John1',
age: 20,
status: 'active',
hobbies: ['gaming']
};
console.log(isEquals(obj2, undefined, { schema })) // true
For optimal security, it’s crucial to manage and store cryptographic keys carefully. Here’s a simple guide to help you maintain the integrity and security of your keys:
-
Store keys in environment variables:
- Place your cryptographic keys in a
.env
file. This file should not be included in your version control system (e.g., Git). - Example:
ENCRYPTION_KEY=my-secret-key
- Place your cryptographic keys in a
-
Use dotenv for secure key management:
- Install
dotenv
if you haven't already:npm install dotenv
- Load your environment variables in your application using
dotenv
:require('dotenv').config() || import * as dotenv from 'dotenv'; dotenv.config() const encryptionKey = process.env.ENCRYPTION_KEY
- This ensures that the key is only accessible within your application's runtime, not hard-coded directly in the codebase.
- Install
-
Rotate keys regularly:
- Regularly update your encryption keys to prevent potential unauthorized access. Document key rotations in your system for audit purposes.
-
Limit key permissions:
- Restrict access to keys by limiting the permissions of the
.env
file and ensuring only authorized personnel can modify it. - Avoid placing keys directly in source code, as this can expose them in version history and logs.
- Restrict access to keys by limiting the permissions of the
-
Encrypt sensitive data:
- Whenever storing sensitive data, encrypt it with the appropriate keys to prevent unauthorized access if it’s compromised.
encrypt(data: string, options?: EncryptOptions): Promise<string>
decrypt(data: string, options?: DecryptOptions): Promise<string>
base64Encode(data: string, key?: string): string
base64Decode(data: string, key?: string): string
tokenGenerator(length: number, type: CharacterSetType): string
isEqual(text1: string, text2: string, options?: IsEqualOptions): Promise<{ isEqual: boolean, method?: string }>
encryptObject(object: EncryptableObject, secretKey?: string): EncryptableObject
decryptObject(object: EncryptableObject, secretKey?: string): EncryptableObject
Contributions are welcome! Here’s how you can contribute:
- Submit issues to report bugs or suggest features.
- Create pull requests to improve the toolkit.
- Share ideas to enhance functionality.
This project is licensed under the MIT License. The MIT License is a permissive open-source license that allows users to freely use, modify, distribute, and sublicense the software, subject to certain conditions. For a full description of the terms and conditions under which this project can be used, modified, and distributed, please refer to the LICENSE file included in the project. By using, modifying, or distributing this project, you agree to abide by the terms outlined in the MIT License.
- Clean and well-documented codebase.
- Regular updates and active maintenance.
- Tailored for developers needing advanced cryptographic utilities.