feat: update publickey.ts
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
const {X509Certificate, createPublicKey} = await import('node:crypto');
|
||||
|
||||
if (Deno.args.length === 0) {
|
||||
console.log("Usage: certificate.ts <certificate|publickey>");
|
||||
console.log("Usage: publickey.ts <certificate|publickey|jwk>");
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
@@ -21,15 +21,31 @@ if (Deno.args.length === 0) {
|
||||
// console.log(x509.publicKey.export({format: "pem", type: "spki"}));
|
||||
// }
|
||||
|
||||
try {
|
||||
const publicKey = createPublicKey(Deno.args[0]);
|
||||
|
||||
function printPublicKey(publicKey) {
|
||||
console.log('JWK:');
|
||||
const exportedJwk = publicKey.export({format: "jwk"});
|
||||
console.log(JSON.stringify(exportedJwk, null, 4));
|
||||
console.log();
|
||||
console.log("PEM:");
|
||||
console.log(publicKey.export({format: "pem", type: "spki"}));
|
||||
} catch (e) {
|
||||
console.error(`Parse certificate or public key failed: ${e}`);
|
||||
}
|
||||
|
||||
const firstArgument = Deno.args[0];
|
||||
try {
|
||||
const publicKey = createPublicKey(firstArgument);
|
||||
printPublicKey(publicKey);
|
||||
Deno.exit(0);
|
||||
} catch (e) {
|
||||
// try jwk
|
||||
try {
|
||||
const key = JSON.parse(firstArgument);
|
||||
const publicKey = createPublicKey({key, format: "jwk"});
|
||||
printPublicKey(publicKey);
|
||||
Deno.exit(0);
|
||||
} catch (e) {
|
||||
// IGNORE
|
||||
}
|
||||
|
||||
console.error(`Parse certificate or public key failed: ${e}`);
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user