-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.html
203 lines (183 loc) · 6.81 KB
/
index.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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Encrypt file</title>
<link
rel="stylesheet"
href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css"
integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T"
crossorigin="anonymous"
>
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="https://github.com/didww/didww-encrypt">DIDWW Encrypt</a>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="">Encrypt file</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/didww-encrypt/test_encryption">Test Encryption</a>
</li>
</ul>
</div>
</nav>
<div class="card m-5">
<div class="card-header">Encrypt file</div>
<div class="card-body">
<div class="form-group row">
<label class="control-label col-md-2" for="public-key-url">Public Key URL</label>
<input
type="text"
required
id="public-key-url"
class="form-control col-md-8"
value="https://sandbox-api.didww.com/v3/public_keys"
>
</div>
<div class="form-group row">
<label class="control-label col-md-2" for="encryption-fingerprint">Fingerprint</label>
<input
type="text"
readonly
id="encryption-fingerprint"
class="form-control col-md-8 mr-2"
>
<button
class="btn btn-secondary form-control col-md-1"
id="encryption-fingerprint-copy-btn"
>
Copy
</button>
</div>
<div class="form-group row">
<label class="control-label col-md-2" for="encrypt-file">Files</label>
<input
type="file"
multiple
id="encrypt-file"
class="encrypted-file-input form-control-file col-md-8 mr-2"
>
<button class="btn btn-secondary form-control col-md-1" id="encrypt-file-clear-btn">Clear</button>
</div>
<div class="form-group row">
<label class="control-label col-md-2" for="encrypt-file">Files Status</label>
<span id="encrypt-file-status" class="col-md-8">Empty</span>
</div>
<div class="form-group" id="encrypted-download-link">
</div>
</div>
</div>
<script
src="https://code.jquery.com/jquery-3.3.1.slim.min.js"
integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo"
crossorigin="anonymous"
></script>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"
integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1"
crossorigin="anonymous"
></script>
<script
src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"
integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM"
crossorigin="anonymous"
></script>
<script src="https://unpkg.com/@didww/[email protected]/dist/browser.min.js"></script>
<script>
function readFile(file, onLoad, onError) {
if (!onError) onError = function (error) {
console.error(error)
}
const reader = new FileReader()
reader.onload = function () {
onLoad(reader.result)
}
reader.onerror = function () {
onError(reader.error)
}
reader.readAsDataURL(file)
return reader
}
function isReadersReady(readers) {
let done = 0
readers.forEach(function (reader) {
if (reader.readyState === FileReader.DONE) done += 1
})
return readers.length === done
}
function abortReaders(readers) {
fileReaders.forEach(function (reader) {
if (reader.readyState !== FileReader.DONE) reader.abort()
})
}
function buildDownloadLink(file, filename) {
const blobUrl = URL.createObjectURL(file)
return $('<a>', { download: filename, href: blobUrl })
.text('Download ' + filename)
.css({ display: 'block' })
}
const fileInput = $('#encrypt-file')
const publicKeyUrlInput = $('#public-key-url')
const fingerprintInput = $('#encryption-fingerprint')
const downloadLinksContainer = $('#encrypted-download-link')
const statusNode = $('#encrypt-file-status')
const copyFingerprintBtn = $('#encryption-fingerprint-copy-btn')
const clearFilesBtn = $('#encrypt-file-clear-btn')
let fileReaders = []
let encryptor = new DidwwEncrypt({
url: publicKeyUrlInput.val()
})
encryptor.getFingerprint().then(function (fingerprint) {
fingerprintInput.val(fingerprint)
})
publicKeyUrlInput.on('change', function () {
fingerprintInput.val('')
encryptor = new DidwwEncrypt({
url: publicKeyUrlInput.val()
})
encryptor.getFingerprint().then(function (fingerprint) {
fingerprintInput.val(fingerprint)
})
fileInput.trigger('change')
})
fileInput.on('change', function () {
downloadLinksContainer.html('')
const files = fileInput[0].files
if (files.length === 0) {
statusNode.text('Empty')
return
}
statusNode.text('Encrypting...')
abortReaders(fileReaders)
fileReaders = []
Array.from(fileInput[0].files).forEach(function (file) {
const reader = readFile(file, function (binary) {
encryptor.encryptContent(binary).then(function (encrypted) {
const encryptedFile = encrypted.toFile()
const link = buildDownloadLink(encryptedFile, file.name + '.enc')
downloadLinksContainer.append(link)
if (isReadersReady(fileReaders)) statusNode.text('Encrypted.')
})
})
fileReaders.push(reader)
})
})
copyFingerprintBtn.on('click', function () {
fingerprintInput[0].select()
document.execCommand('copy')
copyFingerprintBtn.text('Copied').attr('disabled', 'disabled')
setTimeout(function () {
copyFingerprintBtn.text('Copy').removeAttr('disabled')
}, 200)
})
clearFilesBtn.on('click', function () {
fileInput.val('')
fileInput.trigger('change')
})
</script>
</body>
</html>