mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-12 08:54:00 +02:00
c758377188
Also improved SCSS support, which was needed for the master password dialog.
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { RSA } from '@joplin/lib/services/e2ee/types';
|
|
const RnRSA = require('react-native-rsa-native').RSA;
|
|
|
|
interface RSAKeyPair {
|
|
public: string;
|
|
private: string;
|
|
}
|
|
|
|
const rsa: RSA = {
|
|
|
|
generateKeyPair: async (keySize: number): Promise<RSAKeyPair> => {
|
|
const keys: RSAKeyPair = await RnRSA.generateKeys(keySize);
|
|
|
|
// Sanity check
|
|
if (!keys.private) throw new Error('No private key was generated');
|
|
if (!keys.public) throw new Error('No public key was generated');
|
|
|
|
return keys;
|
|
},
|
|
|
|
loadKeys: async (publicKey: string, privateKey: string): Promise<RSAKeyPair> => {
|
|
return { public: publicKey, private: privateKey };
|
|
},
|
|
|
|
encrypt: async (plaintextUtf8: string, rsaKeyPair: RSAKeyPair): Promise<string> => {
|
|
return RnRSA.encrypt(plaintextUtf8, rsaKeyPair.public);
|
|
},
|
|
|
|
decrypt: async (ciphertextBase64: string, rsaKeyPair: RSAKeyPair): Promise<string> => {
|
|
return RnRSA.decrypt(ciphertextBase64, rsaKeyPair.private);
|
|
},
|
|
|
|
publicKey: (rsaKeyPair: RSAKeyPair): string => {
|
|
return rsaKeyPair.public;
|
|
},
|
|
|
|
privateKey: (rsaKeyPair: RSAKeyPair): string => {
|
|
return rsaKeyPair.private;
|
|
},
|
|
|
|
};
|
|
|
|
export default rsa;
|