0% found this document useful (0 votes)
5 views4 pages

Client Encryption and Decryption

Uploaded by

kiit.ashish242
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

Client Encryption and Decryption

Uploaded by

kiit.ashish242
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Request Parameters: -

Parameter Name M/O Data Type Description


data M String JSON Payload needs to be encrypted with a random AES
256-bit symmetric key and pass it in the data parameter or
tag.
key M String The random AES-256-bit symmetric key need to encrypt with
the public certificate, followed by the RSA-OAEP-256
algorithm, and pass it in the key parameter or tag.
bit M integer 0(zero) – it’s a static value for all clients / 1- for millennial

Example Request: -
{
"data": " JSON Payload needs to be encrypted with a random AES 256-bit symmetric key -- (String)”,
"key": " The random AES-256-bit symmetric key needs to encrypt with the public certificate, followed by
the RSA-OAEP-256 algorithm — (string)",
"bit": 0
}

Example AES-256-bit Symmetric key: - (Please don’t use this key’s this is only for your
reference)
1) 41ed35d0934f0c3d0a9f3f36c5b89be60f7714f516381d43242f59299cd6e949
2) 5777441745751c16c46e6b56a44109df13c290d3c533b94c1b8a69d26d7d81a1

Sample encryption Request: -


{
"data": "1D55AE30D705357474E785A4BBD843E62A777A3ED48C8426B34C93320C6DA9CB7EEC750
BD88F67BA86FAD52CDDC57F59409BE05C8395A77EF00F1CCC1599EE92834E350205A66B05E950C49
B68ADAEF443CAEE8387F720FF045D0B127115514445C165CBADE89696E0B9518088797D51C640149
BFDB4DA56B4460849681E3E26FD1DA6C26A62455892F2A5C674249A26058BCECB5D9FC1C84DCD79
967700513FC9A7DF2E021D100219CC3F11A076252DE08E6A8007C67ED973FD38053E333330D6CA54
D0D1B79CE32D9C762231DEADEE8644A2E320B2E46F5E4451C3960202B4",
"key": "7f6f0adc730f9942fd301f0f4578aed5235b877335801492f299516d98fd71173fcb3247ce8778
41b87821494e7e7ffb28b091582d6f3b6ee6cdebdfe8912c454fba0e31fb6ae9f20f8795b9d34f5a3fc3cab
398b03c09fb5d4505baca4f7eb6e7bd9b2d75bae2fc7097c1fdc72100c7d6ca125f357d25562e90899d6d
191943882b6f1d824279f637ca638c7c2d3cb06c764042d1c3d747dbc901fff8232855ed47fa1c86ef2309
d44f6dad93c4048fd9a0c9007e540374eba0b23c5a68f3373ffa8b870c6911504b71dbb656fe028ccf153a
474ee2a9c354c4c2c879dee23249eaad2c743539d994aa7f7759b99369a9f923990660ef49b676159f559
6a377",
"bit": 0
}
Response Parameters: -

Parameter Name M/O Data Type Description


data String API will send an encrypted response by using the same
AES-256-bit symmetric key. which is used to encrypt
the request JSON payload.

NOTE: - Only in success scenarios & business failures API response will be in an encrypted format, for technical
failures response of API is in JSON.

Example Response: -

{
"data": " API will send an encrypted response by using the same AES-256-bit symmetric key. which is used
to encrypt the request JSON payload"
}

Sample Encrypted Response: -

{
"data": "1D55AE30D705357474E785A4BBD843E62A777A3ED48C8426B34C93320C6DA9CB7EEC750
BD88F67BA86FAD52CDDC57F59409BE05C8395A77EF00F1CCC1599EE92834E350205A66B05E950C49
B68ADAEF443CAEE8387F720FF045D0B127115514445C165CBADE89696E0B9518088797D51C640149
BFDB4DA56B4460849681E3E26FD1DA6C26A62455892F2A5C674249A26058BCECB5D9FC1C84DCD79
967700513FC9A7DF2E021D100219CC3F11A076252DE08E6A8007C67ED973FD38053E333330D6CA54
D0D1B79CE32D9C762231DEADEE8644A2E320B2E46F5E4451C3960202B4"
}

Please refer to the attached jar for encryption and decryption.

Decryption logic at our end: - (Reference)

var jose = require('jose');


var privateKey = 'indus-privatekey'; //referring private key
if (privateKey != null) {
[Link](function (error, json) {
if (error) {
[Link]('CustomError', 'Request not in JSON');
} else {
var data = [Link]
var bit = [Link]
var jweobj = [Link]([Link]);
[Link](privateKey);
[Link](jweobj).decrypt(function (error, symmetricKey) { //decrypt the
symmetric key using private key
if (error) {
[Link]('CustomError', 'JWE Decryption Failed with Certificate');
} else {
var aesHexKey
if (bit == 0){aesHexKey = symmetricKey}
if (bit == 1){aesHexKey = [Link]('hex');}
[Link]("mySymmetricKey", aesHexKey);
var jweobj = [Link](data);
[Link]('hex:' + aesHexKey);
[Link](jweobj).decrypt(function (error, plaintext) { //decrypt the payload
if (error) {
[Link]('CustomError', 'JWE Decryption Failed with AES Key');
} else {
var decryptedJson = json
decryptedJson = [Link]([Link]());
[Link](decryptedJson);
}
});
}
});
}
});
}

Encryption Logic at our end: -

var jose = require('jose');


var jweHdr = [Link]('A256GCM'); //supported algorithm for encryption
var mySymmetricKey = [Link]('mySymmetricKey');
[Link]('alg', 'A256KW');
[Link]('hex:' + mySymmetricKey);
[Link](function (error, json) {
if (error) {
[Link]('CustomError', 'Response not in JSON');
} else{
var _my_json_string = [Link](json);
let _my_json_buffer = new Buffer(_my_json_string);
[Link](jweHdr).update(_my_json_buffer).encrypt('compact', function (error,
jweObj) {
if (error) {
[Link]('CustomError', 'JWE Encryption Failed');
} else {
[Link]({"data": jweObj});
}
}
);
}
}
);
IBM Knowledge Centre reference: -

[Link]

You might also like