Guide
Encrypt Decrypt Req Res

Encrypt & Decrypt API Responses and Requests

The following code presents how to encrypt the API responses and decrypt the information received in the API

Generate apiKey

npx generate-key

An .env file is automatically generated or the one you have is overwritten with the apiKey that will sign your hash

Implement corresponding Middleware in app

const express = require('express');
const cors = require('cors');
const { encryptResponse, decryptRequest } = require('apiutils.js');
 
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extends: true }));
app.use(cors());
 
app.use(encryptResponse);
app.use(decryptRequest);
 
 
app.get('/test', (req, res) => {
    res.status(200).json({
        ok: true,
        msg: "Test",
        personalInfo: {
            name: "John",
            lastName: "Smith",
            age: 23
        }
    })
});
 
app.post('/test', (req, res) => {
    res.status(200).json({
        ok: true,
        data: "MSG"
    })
})
 
app.listen(4000, () => {
    return console.log('api running');
});

For encryption and decryption from the front-end you can use our Angular library ng-apiutils-client