-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqcrypt.ts
28 lines (23 loc) · 964 Bytes
/
qcrypt.ts
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
import * as cs from './src/app/services/cipher.service';
import * as readline from 'node:readline/promises';
import { stdin as input, stdout as output } from 'node:process';
import { base64ToBytes } from './src/app/services/utils';
function streamFromStr(str: string): ReadableStream<Uint8Array> {
const data = new TextEncoder().encode(str);
const blob = new Blob([data], { type: 'application/octet-stream' });
return blob.stream();
}
const cipherSvc = new cs.CipherService();
const rl = readline.createInterface({ input, output });
const cipherText = await rl.question('Cipher text (base64): ');
const userCred = await rl.question('Site key (base64): ');
const cipherStream = streamFromStr(cipherText);
const clear = await cipherSvc.decryptStream(
async (lp, lpEnd, hint) => {
return [await rl.question(`Password (hint: ${hint}): `), undefined]
},
base64ToBytes(userCred),
cipherStream
);
rl.close();
console.log(clear);