@shockpkg/ria-packager
Version:
Package for creating Adobe AIR packages
62 lines (58 loc) • 1.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.SecurityKeyPrivateRsa = void 0;
var _nodeForge = require("node-forge");
var _private = require("../private.js");
/**
* SecurityKeyPrivateRsa object.
*/
class SecurityKeyPrivateRsa extends _private.SecurityKeyPrivate {
/**
* RSA private key in PEM format.
*/
/**
* SecurityKeyPrivateRsa constructor.
*
* @param privateKey RSA private key in PEM format.
*/
constructor(privateKey) {
super();
this._privateKey = privateKey;
}
/**
* Sign data.
*
* @param data Data to be signed.
* @param digest Digest algorithm.
* @returns The signature.
*/
sign(data, digest) {
const privateKey = _nodeForge.pki.privateKeyFromPem(this._privateKey);
digest = digest.toLowerCase();
let md;
switch (digest) {
case 'sha1':
{
md = _nodeForge.md.sha1.create();
break;
}
case 'sha256':
{
md = _nodeForge.md.sha256.create();
break;
}
default:
{
throw new Error(`Unsupported digest algorithm: ${digest}`);
}
}
// eslint-disable-next-line unicorn/prefer-code-point
md.update(String.fromCharCode(...data));
const signature = privateKey.sign(md, 'RSASSA-PKCS1-V1_5');
return _nodeForge.util.binary.raw.decode(signature);
}
}
exports.SecurityKeyPrivateRsa = SecurityKeyPrivateRsa;
//# sourceMappingURL=rsa.js.map