mirror of
https://github.com/node-ebics/node-ebics-client.git
synced 2024-12-25 05:41:49 +00:00
Update GenericUploadOrder.js file
Fix constructor Fix signatureValue method Fix encryptedOrderSignature method Add encryptedOrderdata method Add _pad method
This commit is contained in:
parent
5ace213723
commit
7979999466
@ -2,6 +2,7 @@
|
||||
|
||||
const zlib = require('zlib');
|
||||
const crypto = require("crypto");
|
||||
|
||||
const js2xmlparser = require('js2xmlparser');
|
||||
|
||||
const GenericOrder = require('./GenericOrder');
|
||||
@ -10,8 +11,8 @@ module.exports = class GenericUploadOrder extends GenericOrder {
|
||||
constructor(client, document) {
|
||||
super(client);
|
||||
|
||||
this._document = document;
|
||||
this._key = crypto.randomBytes(16);
|
||||
this._document = document;
|
||||
this._key = crypto.randomBytes(16);
|
||||
|
||||
this._schema.body = {
|
||||
DataTransfer: {
|
||||
@ -21,7 +22,7 @@ module.exports = class GenericUploadOrder extends GenericOrder {
|
||||
"@": { Version: "E002", Algorithm: "http://www.w3.org/2001/04/xmlenc#sha256" },
|
||||
"#": this.client.bankE().publicDigest()
|
||||
},
|
||||
TransactionKey: Buffer.from(this.client.bankE().publicEncrypt(this._key)).toString('base64'),
|
||||
TransactionKey: this.client.bankE().publicEncrypt(this._key).toString('base64'),
|
||||
},
|
||||
SignatureData: {
|
||||
"@": { authenticate: true },
|
||||
@ -50,14 +51,29 @@ module.exports = class GenericUploadOrder extends GenericOrder {
|
||||
};
|
||||
|
||||
signatureValue() {
|
||||
const digested = crypto.createHash('sha256').update(this._document).digest();
|
||||
const digested = crypto.createHash('sha256').update(this._document.replace(/\n|\r/g, "")).digest();
|
||||
|
||||
return this.client.a().sign(digested);
|
||||
};
|
||||
|
||||
encryptedOrderSignature() {
|
||||
const dst = zlib.deflateSync(this.orderSignature());
|
||||
const cipher = crypto.createCipheriv('aes-128-cbc', this._key, Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,])).setAutoPadding(false);
|
||||
const encrypted = cipher.update(dst) + cipher.final();
|
||||
encryptedOrderData() {
|
||||
const dst = zlib.deflateSync(this._document.replace(/\r|\n/g, ""));
|
||||
const cipher = crypto.createCipheriv('aes-128-cbc', this._key, Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,])).setAutoPadding(false);
|
||||
|
||||
return Buffer.from(encrypted).toString('base64');
|
||||
return Buffer.concat([cipher.update(this._pad(dst)), cipher.final()]).toString('base64');
|
||||
}
|
||||
|
||||
encryptedOrderSignature() {
|
||||
const dst = zlib.deflateSync(this.orderSignature());
|
||||
const cipher = crypto.createCipheriv('aes-128-cbc', this._key, Buffer.from([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,])).setAutoPadding(false);
|
||||
|
||||
return Buffer.concat([cipher.update(this._pad(dst)), cipher.final()]).toString('base64');
|
||||
};
|
||||
|
||||
_pad(d) {
|
||||
const dLen = d.length;
|
||||
const len = 16 * ( Math.trunc(dLen / 16) + 1 );
|
||||
|
||||
return Buffer.concat([d, Buffer.from(Buffer.from([0]).toString().repeat(len - dLen - 1)), Buffer.from([len-dLen])]);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user