Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gquittet/easy-nodecrypt
A simple nodejs library that makes life easier when you want to encrypt and decrypt string to multiple encodings.
https://github.com/gquittet/easy-nodecrypt
decrypt easy encrypt javascript node nodejs simple simply typescript
Last synced: 6 days ago
JSON representation
A simple nodejs library that makes life easier when you want to encrypt and decrypt string to multiple encodings.
- Host: GitHub
- URL: https://github.com/gquittet/easy-nodecrypt
- Owner: gquittet
- Created: 2019-06-03T21:20:26.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-08-11T01:55:25.000Z (over 3 years ago)
- Last Synced: 2024-12-25T19:33:31.593Z (11 days ago)
- Topics: decrypt, easy, encrypt, javascript, node, nodejs, simple, simply, typescript
- Language: TypeScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# NodeCrypt
A simple nodejs library that makes life easier when you want to encrypt and decrypt string to multiple encodings.
This library was written in pure NodeJS with TypeScript.
## How to use
- With IV
Create a new instance of NodeCryptIV
```javascript
const NodeCryptIV = require('easy-nodecrypt').NodeCryptIV;
```
- Random mode
```javascript
const nodeCryptIV = new NodeCryptIV({ secret: 'mysecret' });
const encrypted = nodeCryptIV.encrypt('Pika Pika!').toBase64();
console.log(encrypted); // emlSWvnh7cUwkEvWWeZafcR3Kp8YJafoRoJvJBQ_t38const decrypted = nodeCryptIV.decrypt(encrypted);
console.log(decrypted); // Pika Pika!
```- No random mode
You can give the IV with an environment variable (NODECRYPT_IV) or directly in the NodeCryptIV instance. The function use first the IV in parameter and if it's not exist, it use the environment variable.
The IV must have a length of 16 characters.
```javascript
const nodeCryptIV = new NodeCryptIV({ secret: 'mysecret', iv: 'totototototototo' });
const encrypted = nodeCryptIV.encrypt('Pika Pika!').toBase64();
console.log(encrypted); // dG90b3RvdG90b3RvdG90b8bCKJ7SMuOaSWvijqvujXMconst decrypted = nodeCryptIV.decrypt(encrypted);
console.log(decrypted); // Pika Pika!
```- Without IV
Create a new instance of NodeCrypt
```javascript
const NodeCrypt = require('easy-nodecrypt').NodeCrypt;
``````javascript
const nodeCrypt = new NodeCrypt('mysecret');
const encrypted = nodeCrypt.encrypt('Pika Pika!').toBase64();
console.log(encrypted); // spsAgpAHVSClkOKb0LTT8Qconst decrypted = nodeCrypt.decrypt(encrypted);
console.log(decrypted); // Pika Pika!
```## Tips and trikcs
- If you want to decrypt a value with another instance of the library, don't forget to specify the encoding to use:
```javascript
// Encrypt value.
const nodeCrypt = new NodeCrypt('mysecret');
const encrypted = nodeCrypt.encrypt('Pika Pika!').toBase64();// Decrypt value with the same instance.
const decrypted = nodeCrypt.decrypt(encrypted);// Decrypt value with another instance.
const newInstance = new NodeCrypt('mysecret');
// Specify the encoding of the encrypted text.
newInstance.encoding = 'base64';
newInstance.decrypt(encrypted);
```## Environements variables
You can give the above values by environements variables:
| Environement variable | Code variable | Class |
|:----|:----:|----:|
|NODECRYPT_SECRET|secret| NodeCrypt, NodeCryptIV |
|NODECRYPT_IV|iv| NodeCryptIV |## Author
Guillaume Quittet
[https://www.linkedin.com/in/gquittet/](https://www.linkedin.com/in/gquittet/)
## Give me a coffee ☕
[https://paypal.me/gquittet](https://paypal.me/gquittet)