@weiliang79/ubl-builder
Version:
Tool to create xml documents with UBL 2.1 standard
215 lines • 7.15 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.SHA512 = exports.SHA1 = exports.SHA384 = exports.SHA256 = void 0;
const crypto = __importStar(require("crypto"));
/* tslint:disable:max-classes-per-file */
class SHA256 {
/**
*
* @param content string to hash
* @param inputEncoding input encoding "utf8" | "base64" | "binary" | "hex"
* @param outputEncoding output "utf8" | "base64" | "binary" | "hex"
*/
getHash(content, inputEncoding = 'utf8', outputEncoding = 'base64') {
const shasum = crypto.createHash('sha256');
shasum.update(content, inputEncoding);
const res = shasum.digest(outputEncoding);
return res;
}
getAlgorithmName() {
return 'http://www.w3.org/2001/04/xmlenc#sha256';
}
}
exports.SHA256 = SHA256;
class SHA384 {
/**
*
* @param content string to hash
* @param inputEncoding input encoding "utf8" | "base64" | "binary" | "hex"
* @param outputEncoding output encoding "utf8" | "base64" | "binary" | "hex"
*/
getHash(content, inputEncoding = 'utf8', outputEncoding = 'hex') {
const shasum = crypto.createHash('SHA384');
shasum.update(content, inputEncoding);
const res = shasum.digest(outputEncoding);
return res;
}
getAlgorithmName() {
return 'http://www.w3.org/2001/04/xmlenc#sha256';
}
}
exports.SHA384 = SHA384;
class SHA1 {
/**
*
* @param content string to hash
* @param inputEncoding input encoding "utf8" | "base64" | "binary" | "hex"
* @param outputEncoding output encoding "utf8" | "base64" | "binary" | "hex"
*/
getHash(content, inputEncoding = 'utf8', outputEncoding = 'base64') {
const shasum = crypto.createHash('sha1');
shasum.update(content, inputEncoding);
const res = shasum.digest(outputEncoding);
return res;
}
getAlgorithmName() {
return 'http://www.w3.org/2000/09/xmldsig#sha1';
}
}
exports.SHA1 = SHA1;
class SHA512 {
/**
*
* @param content string to hash
* @param inputEncoding input encoding "utf8" | "base64" | "binary" | "hex"
* @param outputEncoding output encoding "utf8" | "base64" | "binary" | "hex"
*/
getHash(content, inputEncoding = 'utf8', outputEncoding = 'base64') {
const shasum = crypto.createHash('sha512');
shasum.update(content, inputEncoding);
const res = shasum.digest(outputEncoding);
return res;
}
getAlgorithmName() {
return 'http://www.w3.org/2001/04/xmlenc#sha512';
}
}
exports.SHA512 = SHA512;
// /**
// * Signature algorithm implementation
// *
// */
// function RSASHA1() {
// /**
// * Sign the given string using the given key
// *
// */
// this.getSignature = function(signedInfo, signingKey) {
// var signer = crypto.createSign("RSA-SHA1")
// signer.update(signedInfo)
// var res = signer.sign(signingKey, 'base64')
// return res
// }
// /**
// * Verify the given signature of the given string using key
// *
// */
// this.verifySignature = function(str, key, signatureValue) {
// var verifier = crypto.createVerify("RSA-SHA1")
// verifier.update(str)
// var res = verifier.verify(key, signatureValue, 'base64')
// return res
// }
// this.getAlgorithmName = function() {
// return "http://www.w3.org/2000/09/xmldsig#rsa-sha1"
// }
// }
// /**
// * Signature algorithm implementation
// *
// */
// function RSASHA256() {
// /**
// * Sign the given string using the given key
// *
// */
// this.getSignature = function(signedInfo, signingKey) {
// var signer = crypto.createSign("RSA-SHA256")
// signer.update(signedInfo)
// var res = signer.sign(signingKey, 'base64')
// return res
// }
// /**
// * Verify the given signature of the given string using key
// *
// */
// this.verifySignature = function(str, key, signatureValue) {
// var verifier = crypto.createVerify("RSA-SHA256")
// verifier.update(str)
// var res = verifier.verify(key, signatureValue, 'base64')
// return res
// }
// this.getAlgorithmName = function() {
// return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256"
// }
// }
// /**
// * Signature algorithm implementation
// *
// */
// function RSASHA512() {
// /**
// * Sign the given string using the given key
// *
// */
// this.getSignature = function(signedInfo, signingKey) {
// var signer = crypto.createSign("RSA-SHA512")
// signer.update(signedInfo)
// var res = signer.sign(signingKey, 'base64')
// return res
// }
// /**
// * Verify the given signature of the given string using key
// *
// */
// this.verifySignature = function(str, key, signatureValue) {
// var verifier = crypto.createVerify("RSA-SHA512")
// verifier.update(str)
// var res = verifier.verify(key, signatureValue, 'base64')
// return res
// }
// this.getAlgorithmName = function() {
// return "http://www.w3.org/2001/04/xmldsig-more#rsa-sha512"
// }
// }
// function HMACSHA1() {
// this.verifySignature = function(str, key, signatureValue) {
// var verifier = crypto.createHmac("SHA1", key);
// verifier.update(str);
// var res = verifier.digest('base64');
// return res === signatureValue;
// };
// this.getAlgorithmName = function() {
// return "http://www.w3.org/2000/09/xmldsig#hmac-sha1";
// };
// this.getSignature = function(signedInfo, signingKey) {
// var verifier = crypto.createHmac("SHA1", signingKey);
// verifier.update(signedInfo);
// var res = verifier.digest('base64');
// return res;
// };
// }
//# sourceMappingURL=shas.js.map