-
- // TODO: Use following APIs instead of JSEncryptLib
- decryptWithPrivateKey(encryptedString, pincode) {
- const key = crypto.createPrivateKey({
- key: this.privateKey,
- format: "pem",
- passphrase: pincode
- });
- const encrypted = crypto.privateDecrypt(key, Buffer.from(encryptedString, "base64"));
- const decryptedString = encrypted.toString("utf8");
- return decryptedString;
- }
-
- encryptWithPrivateKey(plain, pincode) {
- const keyp = crypto.createPrivateKey({
- key: this.privateKey,
- format: "pem",
- passphrase: pincode
- });
- const encrypted = crypto.privateEncrypt(keyp, Buffer.from(plain));
- const encryptedString = encrypted.toString("base64");
- return encryptedString;
- }
-
- decryptWithPublicKey(encryptedString) {
- const decrypted = crypto.publicDecrypt(this.publicKey, Buffer.from(encryptedString, "base64"));
- const decryptedString = decrypted.toString("utf8");
- return decryptedString;
- }
-
- encryptWithPublicKey(plain) {
- const encrypted = crypto.publicEncrypt(this.publicKey, Buffer.from(plain));
- const encryptedString = encrypted.toString("base64");
- return encryptedString;
- }
-
- getPrivateKey() {
- console.log(`${TAG} getPrivateKey`);
- return this.privateKey;
- }
-
- getPublicKey() {
- console.log(`${TAG} getPublicKey`);
- return this.publicKey;
- }