Encryption
Asymmetric cryptography will be used to ensure all payloads exchanged with the gateway are protected.
The payload will be encrypted with a public key. The public key for encryption needs to be shared with the client. The bolttech API will then decrypt all requests with the private key.
No private keys will be shared, only public keys.
About the public keys
The bolttech API consumer should create an RSA key pair:
Asym Cryptography Algo: RSA
Asym Cryptography key size: 2048 or 4096
Private keys should be kept in secure and offline storage. Public keys will be shared between teams.
Sample with Node.js
Encrypting Payload
First we need to encrypt the payload:
/**
* Install the NODE RSA with the command
* npm i node-rsa
* OR
* yarn add node-rsa
*/
const NodeRSA = require("node-rsa");
/** This is a public key that will be shared by bolttech API team **/
const rsa = new NodeRSA("public key provided by bolttech API team");
/** A example of payment payload **/
const payload = {
quoteRefCode: "RefQuote00001",
locale: "en",
applicant: {
firstName: "Bolttech",
lastName: "Gateway",
phoneNumber: "+351012345678",
email: "[email protected]",
idType: "",
idNumber: "",
dateOfBirth: "1996/11/18",
address: "Address 1",
address2: "Address 2",
district: "Porto",
province: "Porto",
postcode: "410000",
},
insuredPerson: {
sameAsApplicant: true,
firstName: "",
lastName: "",
dateOfBirth: "",
phoneNumber: "",
email: "",
idType: "",
idNumber: "",
address: "",
address2: "",
district: "",
province: "",
postcode: "",
},
product: {
countryCode: "VN",
productName: "device-protection-insurance",
productId:
"DPI-AMS-a69ed45ffdc840acc2f8896ebc5130da169866d1993c1fd6aef819db4b06cc70",
priceWithoutTaxes: "100",
priceWithTaxes: "150",
},
productDetails: {
imei: "861248007147070",
activationDate: "2019/01/08",
purchasePrice: "3350",
diagnosticId: "",
deviceMake: "Apple",
deviceModel: "Iphone Xr",
},
payment: {
paymentTransactionId: "17845651",
paymentAmount: "150",
paymentCurrency: "VND",
paymentTimestamp: "1607472000",
},
};
// Encrypting data
const encryptedData = rsa.encrypt(JSON.stringify(payload), "base64");
/** This encrypted data needs to be signed before sending to the Gateway **/
console.log(encryptedData);