Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80556 views
1
// from https://github.com/indutny/self-signed/blob/gh-pages/lib/asn1.js
2
// Fedor, you are amazing.
3
4
var asn1 = require('asn1.js');
5
6
var RSAPrivateKey = asn1.define('RSAPrivateKey', function() {
7
this.seq().obj(
8
this.key('version').int(),
9
this.key('modulus').int(),
10
this.key('publicExponent').int(),
11
this.key('privateExponent').int(),
12
this.key('prime1').int(),
13
this.key('prime2').int(),
14
this.key('exponent1').int(),
15
this.key('exponent2').int(),
16
this.key('coefficient').int()
17
);
18
});
19
exports.RSAPrivateKey = RSAPrivateKey;
20
21
var RSAPublicKey = asn1.define('RSAPublicKey', function() {
22
this.seq().obj(
23
this.key('modulus').int(),
24
this.key('publicExponent').int()
25
);
26
});
27
exports.RSAPublicKey = RSAPublicKey;
28
29
var PublicKey = asn1.define('SubjectPublicKeyInfo', function() {
30
this.seq().obj(
31
this.key('algorithm').use(AlgorithmIdentifier),
32
this.key('subjectPublicKey').bitstr()
33
);
34
});
35
exports.PublicKey = PublicKey;
36
37
var AlgorithmIdentifier = asn1.define('AlgorithmIdentifier', function() {
38
this.seq().obj(
39
this.key('algorithm').objid(),
40
this.key('none').null_().optional(),
41
this.key('curve').objid().optional(),
42
this.key('params').seq().obj(
43
this.key('p').int(),
44
this.key('q').int(),
45
this.key('g').int()
46
).optional()
47
);
48
});
49
50
var PrivateKeyInfo = asn1.define('PrivateKeyInfo', function() {
51
this.seq().obj(
52
this.key('version').int(),
53
this.key('algorithm').use(AlgorithmIdentifier),
54
this.key('subjectPrivateKey').octstr()
55
);
56
});
57
exports.PrivateKey = PrivateKeyInfo;
58
var EncryptedPrivateKeyInfo = asn1.define('EncryptedPrivateKeyInfo', function() {
59
this.seq().obj(
60
this.key('algorithm').seq().obj(
61
this.key('id').objid(),
62
this.key('decrypt').seq().obj(
63
this.key('kde').seq().obj(
64
this.key('id').objid(),
65
this.key('kdeparams').seq().obj(
66
this.key('salt').octstr(),
67
this.key('iters').int()
68
)
69
),
70
this.key('cipher').seq().obj(
71
this.key('algo').objid(),
72
this.key('iv').octstr()
73
)
74
)
75
),
76
this.key('subjectPrivateKey').octstr()
77
);
78
});
79
80
exports.EncryptedPrivateKey = EncryptedPrivateKeyInfo;
81
82
var DSAPrivateKey = asn1.define('DSAPrivateKey', function() {
83
this.seq().obj(
84
this.key('version').int(),
85
this.key('p').int(),
86
this.key('q').int(),
87
this.key('g').int(),
88
this.key('pub_key').int(),
89
this.key('priv_key').int()
90
);
91
});
92
exports.DSAPrivateKey = DSAPrivateKey;
93
94
exports.DSAparam = asn1.define('DSAparam', function () {
95
this.int();
96
});
97
var ECPrivateKey = asn1.define('ECPrivateKey', function() {
98
this.seq().obj(
99
this.key('version').int(),
100
this.key('privateKey').octstr(),
101
this.key('parameters').optional().explicit(0).use(ECParameters),
102
this.key('publicKey').optional().explicit(1).bitstr()
103
);
104
});
105
exports.ECPrivateKey = ECPrivateKey;
106
var ECParameters = asn1.define('ECParameters', function() {
107
this.choice({
108
namedCurve: this.objid()
109
});
110
});
111
112
exports.signature = asn1.define('signature', function() {
113
this.seq().obj(
114
this.key('r').int(),
115
this.key('s').int()
116
);
117
});
118
119