2022-10-23 21:53:34 +00:00
|
|
|
import * as plugins from './smartcrypto.plugins.js';
|
2019-10-01 13:27:21 +00:00
|
|
|
|
|
|
|
export class PublicKey {
|
|
|
|
// STATIC
|
|
|
|
public static createFromPrivateKey(pemString: string) {
|
|
|
|
const privateKey = plugins.nodeForge.pki.publicKeyFromPem(pemString);
|
|
|
|
return new PublicKey(privateKey);
|
|
|
|
}
|
|
|
|
|
2019-10-01 17:41:34 +00:00
|
|
|
public static fromPemString(pemString: string) {
|
|
|
|
return new PublicKey(plugins.nodeForge.pki.publicKeyFromPem(pemString));
|
|
|
|
}
|
|
|
|
|
2019-10-01 13:27:21 +00:00
|
|
|
// INSTANCE
|
|
|
|
public forgePublicKey: plugins.nodeForge.pki.PublicKey;
|
|
|
|
|
2019-10-01 17:28:50 +00:00
|
|
|
constructor(publicKeyArg: plugins.nodeForge.pki.PublicKey) {
|
2019-10-01 13:27:21 +00:00
|
|
|
this.forgePublicKey = publicKeyArg;
|
|
|
|
}
|
|
|
|
|
|
|
|
public toPemString(): string {
|
|
|
|
return plugins.nodeForge.pki.publicKeyToPem(this.forgePublicKey);
|
|
|
|
}
|
2024-02-09 16:52:13 +00:00
|
|
|
|
|
|
|
public toOpenSSH(): string {
|
|
|
|
return plugins.nodeForge.ssh.publicKeyToOpenSSH(this.forgePublicKey, 'user@host');
|
|
|
|
}
|
2019-10-01 17:28:50 +00:00
|
|
|
}
|