-
-
Notifications
You must be signed in to change notification settings - Fork 645
/
Copy patheckey2hex
executable file
·57 lines (49 loc) · 1.5 KB
/
eckey2hex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env node
/*
* eckey2hex - read PKCS#1/5/8 PEM EC private or public key and show key in hexadecimal
*
* Copyright (c) 2020 Kenji Urushima (kenji.urushima@gmail.com)
*
* This software is licensed under the terms of the MIT License.
* https://kjur.github.io/jsrsasign/license
*
* The above copyright and license notice shall be
* included in all copies or substantial portions of the Software.
*
* Please use '-h' option for this script usage.
* ---------------------------------------------------------
* DESCRIPTION
* read PKCS#1/5/8 PEM EC private or public key and show key in hexadecimal
*
* USAGE
* % eckey2hex private.key
* private key = 1234abcd...
* public key = 04abcd...
* % eckey2hex public.key
* public key = 04abcd...
*/
var program = require('commander');
var rs = require('jsrsasign');
var rsu = require('jsrsasign-util');
var path = require('path');
program
.version('1.0.0 (2020-APr-12)')
.description('read EC key and show key in hexadecimal string')
.usage(' ec-key-file')
.parse(process.argv);
if (program.args.length != 1)
throw "wrong number of arguments";
var inFile = program.args[program.args.length - 1];
var pem;
try {
pem = rsu.readFile(inFile);
} catch (ex) {
throw "can't read file: " + inFile
}
var key = rs.KEYUTIL.getKey(pem);
if (key instanceof rs.KJUR.crypto.ECDSA) {
if (key.prvKeyHex != null)
console.log("private key = " + key.prvKeyHex);
if (key.pubKeyHex != null)
console.log("public key = " + key.pubKeyHex);
}