|
@@ -2,6 +2,7 @@ import { Injectable } from "@angular/core";
|
|
|
import { TwitterApiProvider } from "../twitter-api/twitter-api";
|
|
|
import { P2pStorageIpfsProvider } from "../p2p-storage-ipfs/p2p-storage-ipfs";
|
|
|
import { Storage } from "@ionic/storage";
|
|
|
+import NodeRSA from "node-rsa";
|
|
|
|
|
|
@Injectable()
|
|
|
export class CryptoProvider {
|
|
@@ -124,4 +125,18 @@ export class CryptoProvider {
|
|
|
const privateKey = await this.storage.get("privateKey");
|
|
|
return privateKey.length > 0;
|
|
|
}
|
|
|
+
|
|
|
+ public encrypt(plainText: string, privateKey: string) {
|
|
|
+ const key = new NodeRSA(
|
|
|
+ `-----BEGIN PRIVATE KEY-----${privateKey}-----END PRIVATE KEY-----`
|
|
|
+ );
|
|
|
+ return key.encryptPrivate(plainText, "base64");
|
|
|
+ }
|
|
|
+
|
|
|
+ public decrypt(encryptedMessage: string, publicKey: string): string {
|
|
|
+ const key = new NodeRSA(
|
|
|
+ `-----BEGIN PUBLIC KEY-----${publicKey}-----END PUBLIC KEY-----`
|
|
|
+ );
|
|
|
+ return key.decryptPublic(encryptedMessage).toString();
|
|
|
+ }
|
|
|
}
|