-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrsa.ts
36 lines (27 loc) · 861 Bytes
/
rsa.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
29
30
31
32
33
34
35
36
import * as cryptico from 'cryptico-js/dist/cryptico.browser.js';
import { RSAKey } from './types';
/**
* This class is responsible for generating RSA keys from a passphrase (Super PIN)
* https://github.com/phpmycoder/cryptico-node
*/
export class RSA {
bits: number;
constructor(bits?: number) {
this.bits = bits || 1024;
}
generateKey(passphrase: string) {
return cryptico.generateRSAKey(passphrase, this.bits);
}
encrypt(message: string, receiverPublicKey: string, senderKey?: RSAKey) {
return cryptico.encrypt(message, receiverPublicKey, senderKey);
}
publicKeyID(publicKey: string) {
return cryptico.publicKeyID(publicKey);
}
decrypt(message: string, privateKey: RSAKey) {
return cryptico.decrypt(message, privateKey);
}
publicKeyString(key: RSAKey) {
return cryptico.publicKeyString(key);
}
}