crypto#createPublicKey TypeScript Examples
The following examples show how to use
crypto#createPublicKey.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Rsa4096Pss.ts From arbundles with Apache License 2.0 | 6 votes |
constructor(private _key: string, public pk?: string) {
if (!pk) {
this.pk = createPublicKey({
key: _key,
type: "pkcs1",
format: "pem",
})
.export({
format: "pem",
type: "pkcs1",
})
.toString();
}
}
Example #2
Source File: cloud-kms-signer.ts From cloud-cryptographic-wallet with MIT License | 6 votes |
async getPublicKey(): Promise<PublicKey> {
if (this.cachePublicKey) {
return this.cachePublicKey;
}
const [publicKeyResponse] = await this.client.getPublicKey({
name: this.name,
});
if (publicKeyResponse.name !== this.name) {
throw new Error(`CloudKmsSigner: incorrect name. actual: ${this.name}`);
}
if (publicKeyResponse.pem == undefined) {
throw new Error("CloudKmsSigner: publicKeyResponse.pem is undefined.");
}
if (
crc32c(Buffer.from(publicKeyResponse.pem)) !==
Number(publicKeyResponse.pemCrc32c?.value)
) {
throw new Error(
"CloudKmsSigner: failed to validate of crc32c publicKeyResponse.pem."
);
}
const key = createPublicKey({ key: publicKeyResponse.pem, format: "pem" });
const buffer = key.export({ format: "der", type: "spki" });
const bytes = Bytes.fromString(buffer.toString("hex"));
const rawPublicKey = parsePublicKey(bytes.buffer);
const publicKey = PublicKey.fromBytes(Bytes.fromArrayBuffer(rawPublicKey));
this.cachePublicKey = publicKey;
return publicKey;
}
Example #3
Source File: Util.ts From vircadia-metaverse with Apache License 2.0 | 6 votes |
// The public_key is sent as a binary (DER) form of a PKCS1 key.
// To keep backward compatibility, we convert the PKCS1 key into a SPKI key in PEM format
// ("PEM" format is "Privacy Enhanced Mail" format and has the "BEGIN" and "END" text included).
export function convertBinKeyToPEM(pBinKey: Buffer): string {
// Convert the passed binary into a crypto.KeyObject
const publicKey = createPublicKey( {
key: pBinKey,
format: 'der',
type: 'pkcs1'
});
// Convert the public key to 'SubjectPublicKeyInfo' (SPKI) format as a PEM string
const convertedKey = publicKey.export({ type: 'spki', format: 'pem' });
return convertedKey as string;
}