1.0.0 • Published 9 months ago

cipher-sys v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

Cipher System

Cipher System is a utility package built with Node.js and TypeScript, providing cryptographic functions, password management, and date/time manipulation utilities.

Features

  • Encryption & Decryption: Securely encrypt and decrypt text using AES-256-CBC.
  • Password Generation: Generate secure random passwords with customizable length and character sets.
  • Password Strength Validation: Check if a password meets defined strength criteria.
  • UUID Generation: Generate unique identifiers (UUIDs).
  • Date Formatting: Format dates according to specified locales and options.
  • Time Conversion: Convert time between hours, minutes, seconds, and milliseconds.

Installation

You can install the package via npm or yarn:

npm install cipher-sys
yarn add cipher-sys

Usage

Here's a brief overview of how to use the Cipher System.

Encryption and Decryption

import { Cipher } from 'cipher-sys';

const cipher = new Cipher();
const password = 'myPassword@';
const passKey = 'systemKey';

// Encrypting a password
const encrypted = cipher.encrypt(password, passKey); // String
console.log('Encrypted:', encrypted);

// Decrypting the password
const decrypted = cipher.decrypt(encrypted, passKey); // String
console.log('Decrypted:', decrypted);

Password Generation

const generatedPassword = cipher.generateSecurePassword(16); // String
console.log('Generated Password:', generatedPassword);

Password Strength Validation

const isStrong = cipher.isStrongPassword('P@ssw0rd123!', {
    minLength: 12,
    minUpperCase: 2,
    minNumbers: 2,
    minSpecialChar: 1
}); // Boolean

console.log('Is strong password:', isStrong);

Options:

OptionTypeDefaultDescription
minLengthnumber8Minimum length of the password.
maxLengthnumber20Maximum length of the password.
minUpperCasenumber1Minimum number of uppercase letters required.
minLowerCasenumber1Minimum number of lowercase letters required.
minNumbersnumber1Minimum number of numeric characters required.
minSpecialCharnumber1Minimum number of special characters required.
minNonAlphaNumericnumber1Minimum number of non-alphanumeric characters required.
minUniqueCharsnumber0Minimum number of unique characters required.
minRepeatCharsnumber0Minimum number of repeated characters allowed.
minConsecutiveCharsnumber0Minimum number of consecutive characters allowed.
minConsecutiveNumericnumber0Minimum number of consecutive numeric characters allowed.
minConsecutiveSpecialCharnumber0Minimum number of consecutive special characters allowed.
minConsecutiveNonAlphaNumericnumber0Minimum number of consecutive non-alphanumeric characters allowed.
minConsecutiveUniqueCharsnumber0Minimum number of consecutive unique characters allowed.

UUID Generation

const uuid = cipher.generateUUID(); // String
console.log('Generated UUID:', uuid);

Date Formatting

const formattedDate = cipher.formatDateWithLocale(new Date(), 'en-US', {
    year: 'numeric',
    month: 'long',
    day: 'numeric'
}); // String

console.log('Formatted Date:', formattedDate);

Options:

OptionTypeDescription
year'numeric', '2-digit'Specifies the year format (full or 2-digit).
month'numeric', '2-digit', 'long', 'short', 'narrow'Specifies the month format (number, long name, short name, or narrow).
day'numeric', '2-digit'Specifies the day format (full or 2-digit).
hour'numeric', '2-digit'Specifies the hour format (12 or 24-hour format).
minute'numeric', '2-digit'Specifies the minute format (full or 2-digit).
second'numeric', '2-digit'Specifies the second format (full or 2-digit).
timeZoneName'short', 'long'Specifies the time zone name format (short or long).

Time Conversion

const milliseconds = cipher.convertToMilliseconds(1, 30, 45); // String
console.log('Milliseconds:', milliseconds);

const time = cipher.convertFromMilliseconds(milliseconds); // Object { hours, minutes, seconds }
console.log('Converted Time:', time);

License

This project is licensed under the MIT License. See the LICENSE file for more information.

Contributing

Contributions are welcome! Please submit a pull request or open an issue to discuss changes.