feat: add publickey.ts
This commit is contained in:
@@ -18,6 +18,13 @@
|
||||
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/print-env.ts",
|
||||
"single_script_file": true
|
||||
},
|
||||
"publickey.ts": {
|
||||
"script_name": "publickey.ts",
|
||||
"script_length": 1138,
|
||||
"script_sha256": "28bfa62a68cf9a2142048f605a0b2e769f89b48c5c25af9bb0f9b6081bcf8954",
|
||||
"script_full_url": "https://git.hatter.ink/hatter/ts-scripts/raw/branch/main/single-scripts/publickey.ts",
|
||||
"single_script_file": true
|
||||
},
|
||||
"sigstore-verify.ts": {
|
||||
"script_name": "sigstore-verify.ts",
|
||||
"script_length": 3511,
|
||||
|
||||
35
single-scripts/publickey.ts
Executable file
35
single-scripts/publickey.ts
Executable file
@@ -0,0 +1,35 @@
|
||||
#!/usr/bin/env -S deno run --allow-env
|
||||
|
||||
// Reference:
|
||||
// - https://docs.deno.com/examples/command_line_arguments/
|
||||
// - https://docs.deno.com/api/node/crypto/~/X509Certificate#property_issuercertificate
|
||||
// - https://docs.deno.com/api/node/crypto/~/createPublicKey
|
||||
|
||||
const {X509Certificate, createPublicKey} = await import('node:crypto');
|
||||
|
||||
if (Deno.args.length === 0) {
|
||||
console.log("Usage: certificate.ts <certificate>");
|
||||
Deno.exit(1);
|
||||
}
|
||||
|
||||
// function tryParseCertificate() {
|
||||
// const x509 = new X509Certificate(Deno.args[0]);
|
||||
//
|
||||
// const exportedJwk = x509.publicKey.export({format: "jwk"});
|
||||
// console.log(JSON.stringify(exportedJwk, null, 4));
|
||||
//
|
||||
// console.log(x509.publicKey.export({format: "pem", type: "spki"}));
|
||||
// }
|
||||
|
||||
try {
|
||||
const publicKey = createPublicKey(Deno.args[0]);
|
||||
|
||||
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}`);
|
||||
}
|
||||
Reference in New Issue
Block a user