forked from kjur/jsrsasign
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtool_asn1encoder.html
executable file
·179 lines (156 loc) · 5.52 KB
/
tool_asn1encoder.html
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<meta http-equiv="X-UA-Compatible" content="chrome=1" />
<meta name="description" content="Online ASN.1 Encoder powered by jsrsasign" />
<link rel="stylesheet" type="text/css" media="screen" href="../stylesheets/stylesheet.css">
<title>Online ASN.1 DER file generator (powered by jsrsasign)</title>
<script language="JavaScript" type="text/javascript" src="../jsrsasign-all-min.js"></script>
<script language="JavaScript" type="text/javascript" src="../test/jquery-1.4.2.min.js"></script>
<script language="JavaScript" type="text/javascript" src="../test/FileSaver.min.js"></script>
<script language="JavaScript" type="text/javascript">
var json_encoct1 = (function() {/*
{"seq": [
{"octstr": {"obj": {"seq": [{"int": 3},{"int":4}]}}},
{"prnstr": "aaa"}
]}
*/}).toString().match(/\/\*([^]*)\*\//)[1];
var json_eck1pub1 = (function() {/*
{"seq": [
{"seq": [
{"oid": {"oid": "1.2.840.10045.2.1"}},
{"oid": {"oid": "1.2.840.10045.3.1.7"}}
]},
{"bitstr": {"hex": "0004a01532a3c0900053de60fbefefcca58793301598d308b41e6f4e364e388c2711bef432c599148c94143d4ff46c2cb73e3e6a41d7eef23c047ea11e60667de425"}}
]}
*/}).toString().match(/\/\*([^]*)\*\//)[1];
var json_ecdsasig1 = (function() {/*
{"bitstr":
{"obj":
{"seq": [
{"int": {"hex": "00df01c4bf58a06b3fa241824b10569a788ddab80b9dd8bb817936468c82d8401e"}},
{"int": {"hex": "00d19175600fd50756f65ead8a0950c1da89b384f47bcf8d62ff917006f7558c27"}}
]}
}
}
*/}).toString().match(/\/\*([^]*)\*\//)[1];
var json_eedn1 = (function() {/*
{"seq": [
{"set": [
{"seq": [
{"oid": {"oid": "2.5.4.6"}},
{"prnstr": {"str": "EE"}}
]}
]},
{"set": [
{"seq": [
{"oid": {"oid": "2.5.4.10"}},
{"utf8str": {"str": "AS Sertifitseerimiskeskus"}}
]}
]},
{"set": [
{"seq": [
{"oid": {"oid": "2.5.4.3"}},
{"utf8str": {"str": "ESTEID-SK 2011"}}
]}
]},
{"set": [
{"seq": [
{"oid": {"oid": "1.2.840.113549.1.9.1"}},
{"ia5str": {"str": "[email protected]"}}
]}
]}
]}
*/}).toString().match(/\/\*([^]*)\*\//)[1];
function _doEncode() {
var f1 = document.form1;
var s = f1.s_in.value;
try {
var json = JSON.parse(s);
var derObj = KJUR.asn1.ASN1Util.newObject(json);
f1.s_out.value = derObj.getEncodedHex();
} catch (ex) {
alert("ERR: " + ex);
}
}
function _doSave() {
var f1 = document.form1;
var hex = f1.s_out.value;
try {
var isFileSaverSupported = !!new Blob;
} catch (e) {
alert("ERROR: FileSaver.js is not supported on your browser");
return;
}
//var blob = new Blob([hex], {type: "text/plain;charset=utf-8"});
//saveAs(blob, "asn1encode.hex.txt");
var rstr = hextorstr(hex);
var blob = new Blob([rstr], {type: "application/octet-stream"});
saveAs(blob, "asn1encode.der");
}
function _setSample() {
var f1 = document.form1;
switch (f1.sample1.value) {
case "encoct1": f1.s_in.value = json_encoct1; _doEncode(); break;
case "eck1pub1": f1.s_in.value = json_eck1pub1; _doEncode(); break;
case "ecdsasig1": f1.s_in.value = json_ecdsasig1; _doEncode(); break;
case "eedn1": f1.s_in.value = json_eedn1; _doEncode(); break;
default: f1.s_in.value = ""; break;
}
}
</script>
</head>
<body>
<!-- HEADER -->
<div id="header_wrap" class="outer">
<header class="inner">
<h1 id="project_title">Online ASN.1 DER file generator</h1>
<h2 id="project_tagline">convert JSON represented ASN.1 structure to ASN.1 data</h2>
</header>
</div>
<!-- MAIN CONTENT -->
<div id="main_content_wrap" class="outer">
<section id="main_content" class="inner">
<!-- now editing -->
<form name="form1">
<h4>(Step1) Fill ASN.1 structure by JSON string. The syntax is defined in <a href="https://kjur.github.io/jsrsasign/api/symbols/KJUR.asn1.ASN1Util.html#.newObject" target="_blank">ASN1Util.newObject</a>.</h4>
<textarea name="s_in" rows="10" cols="100">
{"seq": [
{"octstr": {"obj": {"seq": [{"int": 3},{"int":4}]}}},
{"bitstr": {"obj": {"seq": [{"int": 5},{"int":6}]}}},
{"prnstr": "aaa"}
]}
</textarea>
<select name="sample1" onChange="_setSample()">
<option value="none"> You can also choose sample input here...
<option value="encoct1"> encapsulated OctetString sample
<option value="eck1pub1"> PKCS#8 ECC public key sample
<option value="ecdsasig1"> BitString encapsulated ECDSA signature value
<option value="eedn1"> distiguished name of Estonian e-Regident ID CA
</select>
<br/>
<input type="button" value="Encode" onClick="_doEncode();"/><br/>
<hr>
<h2>Result of ASN.1 encoded hexadecimal string:</h2>
<textarea name="s_out" cols="100" rows="10" readonly></textarea><br/>
<input type="button" value="Save this as local file" onClick="_doSave();"/><br/>
NOTE: Saving to local file is powered by
<a href="https://github.com/eligrey/FileSaver.js" target="_blank">FileSaver.js</a>.
FileSaver.js supports most of modern browsers.
</form>
<!-- now editing -->
</section>
</div>
<!-- FOOTER -->
<div id="footer_wrap" class="outer">
<footer class="inner">
<p class="copyright">jsjws maintained by <a href="https://github.com/kjur">@kjur</a></p>
<p>Published with <a href="https://pages.github.com">GitHub Pages</a></p>
<div align="center" style="color: white">
Copyright © 2016 Kenji Urushima. All rights reserved.
</div>
</footer>
</div>
</body>
</html>