sdet v0.1.2
SDET
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
- Fork the repository and clone it to your local machine.
- Create a new branch for your feature/fix:
git checkout -b feature-name
. - Make changes and test them thoroughly.
- Ensure that your code follows the existing code style and conventions.
- Update the README and documentation if necessary.
- Commit your changes with descriptive commit messages.
- Push your branch to your fork:
git push origin feature-name
. - 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.