import Certificate from "./certificate.js"; import { Algorithm } from "../types.js"; import Key from "./internal/key.js"; import PublicKey from "./public_key.js"; import forge from "node-forge"; export default class PrivateKey extends Key { /** String PEM contents of private key */ private readonly _pem; /** String password of private key */ private readonly _passPhrase; /** * Public key extracted from private key */ private _publicKey?; /** * Parsed RSA private key cached instance */ private _parsedPrivateKey?; /** * Private key constructor * * @param source - can be a PKCS#8 DER, PKCS#8 PEM or PKCS#5 PEM * @param passPhrase - if empty asume unencrypted/plain private key */ constructor(source: string, passPhrase: string); pem(): string; passPhrase(): string; publicKey(): PublicKey; /** * Sign string data by provider algorithm * * @param data - input data * @param algorithm - algorithm to be used * @returns binary string signature */ sign(data: string, algorithm?: Algorithm): string; belongsTo(certificate: Certificate): boolean; belongsToPEMCertificate(certificate: string): boolean; callOnPrivateKey(callableFunction: (prv: forge.pki.rsa.PrivateKey) => T): T; changePassPhrase(newPassPhrase: string): PrivateKey; /** * Convert PKCS#8 DER to PKCS#8 PEM * * @param contents - * @param isEncrypted - */ static convertDerToPem(contents: string, isEncrypted: boolean): string; }