https://github.com/SajadTroy/crypash
A lightweight and secure npm package providing a SHA-256 hashing algorithm implementation in pure JavaScript. Use this package to easily hash sensitive data for various applications, ensuring data integrity and security.
https://github.com/SajadTroy/crypash
encryption hashing hashing-algorithm sha256
Last synced: 8 months ago
JSON representation
A lightweight and secure npm package providing a SHA-256 hashing algorithm implementation in pure JavaScript. Use this package to easily hash sensitive data for various applications, ensuring data integrity and security.
- Host: GitHub
- URL: https://github.com/SajadTroy/crypash
- Owner: mrsajadpp
- License: mit
- Created: 2023-12-24T04:21:33.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-24T04:35:35.000Z (over 2 years ago)
- Last Synced: 2024-04-25T18:02:30.208Z (about 2 years ago)
- Topics: encryption, hashing, hashing-algorithm, sha256
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/crypash
- Size: 4.21 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# crypash
A lightweight and secure npm package providing a SHA-256 hashing algorithm implementation in pure JavaScript. Use this package to easily hash sensitive data for various applications, ensuring data integrity and security.
## Installation
You can install `crypash` using npm:
```bash
npm install crypash
```
## Usage
```typescript
// Import the crypash module
const crypash = require('crypash');
const inputText = "Hello, World!";
const algorithmToUse = 'sha256';
const hashedValue = crypash.hash(algorithmToUse, inputText);
if (crypash.check(algorithmToUse, inputText, hashedValue)) {
console.log("Text matches the hashed value.");
} else {
console.log("Text does not match the hashed value.");
}
```
## API
### `hash(algorithm: Algorithm, input: string): string`
This function hashes the input data using the specified algorithm.
- `algorithm` (string): The hashing algorithm to use. Currently, only `'sha256'` is supported.
- `input` (string): The data to be hashed.
Returns the hashed value as a hexadecimal string.
### `check(algorithm: Algorithm, input: string, hashedString: string): boolean`
This function checks if a given text, when hashed, matches a provided hashed value.
- `algorithm` (string): The hashing algorithm to use. Currently, only `'sha256'` is supported.
- `input` (string): The original text.
- `hashedString` (string): The hashed value to compare against.
Returns `true` if the text matches the hashed value, and `false` otherwise.
## Example
```typescript
// Import the crypash module
const crypash = require('crypash');
const inputText = "Example Data";
const algorithmToUse = 'sha256';
const hashedValue = crypash.hash(algorithmToUse, inputText);
if (crypash.check(algorithmToUse, inputText, hashedValue)) {
console.log("Text matches the hashed value.");
} else {
console.log("Text does not match the hashed value.");
}
```
## License
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.