@shockpkg/ria-packager
Version:
Package for creating Adobe AIR packages
66 lines (52 loc) • 1.37 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
import forge from 'node-forge';
import { SecurityKeyPrivate } from "../private.mjs";
/**
* SecurityKeyPrivateRsa constructor.
*/
export class SecurityKeyPrivateRsa extends SecurityKeyPrivate {
/**
* Forge private key.
*/
constructor() {
super();
_defineProperty(this, "_forgePrivateKey", null);
}
/**
* Reset the internal state.
*/
reset() {
this._forgePrivateKey = null;
}
/**
* Read a forge private key.
*
* @param privateKey Forge private key.
*/
readForgeKeyPrivate(privateKey) {
this.reset();
this._forgePrivateKey = privateKey;
}
/**
* Sign data.
*
* @param data Data to be signed.
* @param digest Digest algorithm.
* @returns The signature.
*/
sign(data, digest) {
const privateKey = this._forgePrivateKey;
if (!privateKey) {
throw new Error('Private key not initialized');
}
digest = digest.toLowerCase();
if (digest !== 'sha1') {
throw new Error(`Unsupported digest algorithm: ${digest}`);
}
const md = forge.md.sha1.create();
md.update(forge.util.decode64(data.toString('base64')));
const signature = privateKey.sign(md, 'RSASSA-PKCS1-V1_5');
return Buffer.from(forge.util.encode64(signature), 'base64');
}
}
//# sourceMappingURL=rsa.mjs.map