https://github.com/jihyunlab/crypto
JihyunLab Crypto.
https://github.com/jihyunlab/crypto
aes-cbc aes-gcm cipher crypto decryption encryption
Last synced: 4 months ago
JSON representation
JihyunLab Crypto.
- Host: GitHub
- URL: https://github.com/jihyunlab/crypto
- Owner: jihyunlab
- License: mit
- Created: 2023-11-15T11:42:01.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-17T09:11:51.000Z (about 1 year ago)
- Last Synced: 2025-05-21T14:59:19.386Z (5 months ago)
- Topics: aes-cbc, aes-gcm, cipher, crypto, decryption, encryption
- Language: TypeScript
- Homepage:
- Size: 810 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @jihyunlab/crypto
[](https://www.npmjs.com/package/@jihyunlab/crypto?activeTab=versions) [](https://www.npmjs.com/package/@jihyunlab/crypto) [](https://github.com/jihyunlab/crypto/graphs/commit-activity) [](https://github.com/jihyunlab/crypto/blob/master/LICENSE) [](https://eslint.org) [](https://github.com/prettier/prettier)\
[](https://github.com/jihyunlab/crypto/actions/workflows/build.yml) [](https://github.com/jihyunlab/crypto/actions/workflows/lint.yml) [](https://codecov.io/gh/jihyunlab/crypto)@jihyunlab/crypto was developed to enhance the convenience of implementing cryptographic functionalities in Node.js applications.
The encryption function is implemented with [Crypto](https://nodejs.org/api/crypto.html) in Node.js and provides encryption for AES 256 CBC and AES 256 GCM.
## Installation
```bash
npm i @jihyunlab/crypto
```## Usage
You can easily encrypt and decrypt data with a simple method.
```
import { CIPHER, createCipher } from '@jihyunlab/crypto';const cipher = await createCipher(CIPHER.AES_256_GCM, 'your secret key');
const encrypted = await cipher.encrypt('jihyunlab');
console.log(encrypted); // Uint8Array(37)[51, 174, 20, 84, 12, 141, 173, 206, 249, 11, 59, 112, 88, 223, 163, 211, 128, 234, 102, 116, 16, 224, 175, 45, 46, 52, 186, 141, 15, 243, 9, 120, 64, 27, 135, 169, 65]const decrypted = await cipher.decrypt(encrypted);
console.log(decrypted); // Uint8Array(9)[106, 105, 104, 121, 117, 110, 108, 97, 98]const buffer = Buffer.from(decrypted);
console.log(buffer.toString()); // jihyunlab
```Provides encryption functionality for Uint8Array data.
```
const encrypted = await cipher.encrypt(
new Uint8Array([106, 105, 104, 121, 117, 110, 108, 97, 98])
);
console.log(encrypted); // Uint8Array(37)[185, 95, 254, 103, 109, 250, 109, 50, 8, 218, 251, 74, 215, 108, 74, 86, 177, 82, 144, 154, 156, 120, 128, 169, 112, 236, 153, 23, 253, 164, 238, 159, 236, 17, 85, 26, 75]const decrypted = await cipher.decrypt(encrypted);
console.log(decrypted); // Uint8Array(9)[106, 105, 104, 121, 117, 110, 108, 97, 98]
```You can configure encryption options such as salt and iteration.
```
const cipher = await createCipher(CIPHER.AES_256_GCM, 'your secret key', {
salt: 'salt',
iterations: 256,
});
```## @jihyunlab/web-crypto
[@jihyunlab/web-crypto](https://www.npmjs.com/package/@jihyunlab/web-crypto) implements encryption functionalities for web applications using the same interface as @jihyunlab/crypto.
Consider using @jihyunlab/web-crypto for decrypting encrypted data from @jihyunlab/crypto in web applications, or vice versa.
```
import { CIPHER, createCipher } from '@jihyunlab/web-crypto';const cipher = await createCipher(CIPHER.AES_256_GCM, 'your secret key');
const encrypted = await cipher.encrypt('jihyunlab');
```## Credits
Authored and maintained by JihyunLab <>
## License
Open source [licensed as MIT](https://github.com/jihyunlab/crypto/blob/master/LICENSE).