My First NPM Package
# Description
generate token Encrypted and Decrypted by sodium-plus from string text
## Installing

### Installing as a Node.js Module
With NPM:

```terminal
npm i sodium_token_ppl 
```
# Requirement
sodium-plus
```terminal
npm i sodium-plus
```
# Usage
Example Encrypted in nodejs , like so:
```javascript
const sodium_ppl = require('sodium_token_ppl')
(async function() {
    // input data must be json type
    let test_data = {
        Name : "John",
        Surname : "Doe"
    }
    let result = await sodium_ppl.sodium_Encrypted(test_data)
    console.log(result)
})();

```
The output for Encrypted example is
``` 
encrypt_data: {
  ciphertext: 'U+XyEDNwV5V3o3RwoVRFz8JRb3mOggW4lUSUlQbX6w3Jo25DgBeKQfUJ7noPtCY=', // base64
  nonce: 'O44IKDwZ2hIj6v42qc7FGBG7YEgqIv4C', // base64
  key: 'o0iyAxaBDvpsCYnCTYfilSHRm9haRXv8zK2l2yxMpuo=' // base64
}
```
Example Decrypted in nodejs , like so:
```javascript
const sodium_ppl = require('sodium_token_ppl')
(async function() {
    let data_encrypt = "U+XyEDNwV5V3o3RwoVRFz8JRb3mOggW4lUSUlQbX6w3Jo25DgBeKQfUJ7noPtCY=" // base64
    let nonce = "O44IKDwZ2hIj6v42qc7FGBG7YEgqIv4C" // base64
    let key = "o0iyAxaBDvpsCYnCTYfilSHRm9haRXv8zK2l2yxMpuo=" // base64
    let decrypt_data = await sodium_ppl.sodium_Decrypted(data_encrypt,nonce,key)
    console.log(decrypt_data)
})();

```
The output for this Decrypted is
``` 
{ Name: 'John', Surname: 'Doe' }
```

Example login_ppl in nodejs , like so:
```javascript
const sodium_ppl = require('sodium_token_ppl')
(async function() {
    data_send = {
            "username": "xxxx",
            "password": "xxxx",
        }
    let login_data = await sodium_ppl.login_ppl(data_send)
    // get response data login and insert data login with sodium encrypt in redis
})();

```
Example Decrypted_login_ppl in nodejs , like so:
```javascript
const sodium_ppl = require('sodium_token_ppl')
(async function() {
    username = 'xxxx'
    let de_login_data = await sodium_ppl.data_login_Decrypted(username)
    // get data sodium encrypt by username from redis and decrypt data
})();

```
Example delete data in redis in nodejs , like so:
```javascript
const sodium_ppl = require('sodium_token_ppl')
(async function() {
    username = 'xxxx'
    let result_delete = await sodium_ppl.delete_key_redis(username)
    // delete data in redis by username
})();

```
The output for this delete is
``` 
{
    "result": "OK",
    "messageText_en": "Delete key username 1",
    "status_Code": 200
}
```
Example delete all data in redis in nodejs , like so:
```javascript
const sodium_ppl = require('sodium_token_ppl')
(async function() {
    let result_delete = await sodium_ppl.delete_all_data_redis()
    // delete all data in redis
})();

```

```
The output for this delete is
{
    "result": "OK",
    "messageText_en": "flushdb OK",
    "status_Code": 200
}
```

# Credits
paperless_teams