0.1.2 • Published 12 months ago

sdet v0.1.2

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

SDET

npm version License: MIT

SDET is a lightweight and efficient toolkit for encrypting and decrypting data securely using Node.js's built-in crypto module. It provides easy-to-use functions to encrypt and decrypt data.

Features

  • Easy-to-use: Simple API for encrypting and decrypting data.
  • Secure: Utilizes Node.js's built-in crypto module for robust encryption.

Installation

npm install sdet
pnpm add sdet
yarn add sdet
bun add sdet

Usage

import sdet from "sdet"

// Generate a secret key (hexadecimal format)
const secretKey = sdet.generateKey(32) // Example: generate a 32-byte key

// Encrypt data
const textToEncrypt = "This is a secret message"
const encryptedData = sdet.encrypt(textToEncrypt, secretKey)

// Decrypt data
const decryptedData = sdet.decrypt(encryptedData, secretKey)

console.log("Encrypted:", encryptedData)
console.log("Decrypted:", decryptedData)

// Hash data
const hashedData = await sdet.hashData("sensitive data", 10)

// Compare hashed data
const isMatch = await sdet.compareData("sensitive data", hashedData)

console.log("Hashed data:", hashedData)
console.log("Data match:", isMatch)

API Reference

encrypt(text, secretKey)

Encrypts the provided text using a secret key.

Text: (string) The text to encrypt. Secret Key: (string) The secret key to use for encryption.

Example:

const encryptedText = sdet.encrypt("This is a secret message", "secret-key")

decrypt(encrypted, secretKey)

Decrypts the provided encrypted text using a secret key.

Ecrypted:

  • iv (string): The initialization vector used for encryption.
  • content (string): The encrypted content.

Secret Key: (string) The secret key to use for decryption.

Example:

const decryptedText = sdet.decrypt({ iv: "iv-hex", content: "encrypted-content-hex" }, "secret-key")

generateKey(length)

Generates a random key.

Length: (number | string | bigint) The length of the key to generate.

Example:

const key = sdet.generateKey(32) // Output: a random 32-byte key

hashData(data, saltRounds)

Hashes the provided data using a salt generated with the specified number of rounds.

Data: (string) The data to hash. Salt Rounds: (number) The number of rounds to use for hashing.

Example:

const hashedData = sdet.hashData("sensitive data", 10) // Output: a hashed version of the data

compareData(data, hashedData)

Compares the provided data with the hashed data to check for equality.

Data: (string) The data to compare. Hashed Data: (string) The hashed data to compare against.

Example:

const isMatch = sdet.compareData("sensitive data", "hashed data") // Output: true if the data matches the hashed data, false otherwise

Contributing

Contributions are welcome! If you find any issues or have suggestions for improvement, please open an issue or submit a pull request. Here are some ways you can contribute:

  • Bug Reports: If you find any bugs or unexpected behavior, please open an issue describing the problem.
  • Feature Requests: If you have ideas for new features or improvements, feel free to suggest them by opening an issue.
  • Code Contributions: Contributions to the codebase via pull requests are highly appreciated. Before submitting a pull request, please make sure to follow the contribution guidelines below.

Contribution Guidelines

  1. Fork the repository and clone it to your local machine.
  2. Create a new branch for your feature/fix: git checkout -b feature-name.
  3. Make changes and test them thoroughly.
  4. Ensure that your code follows the existing code style and conventions.
  5. Update the README and documentation if necessary.
  6. Commit your changes with descriptive commit messages.
  7. Push your branch to your fork: git push origin feature-name.
  8. Open a pull request to the main branch of the original repository.

Thank you for contributing to SDET!

License

This project is licensed under the MIT License - see the LICENSE file for details.

0.1.2

12 months ago

0.1.1

1 year ago

0.1.0

1 year ago

0.0.1

1 year ago