Encryption Key Pair

📘

This feature requires the Decrypt & Encrypt permission.

Encryption

Each HandCash user-app relationship forms a unique key pair:

User 1 + App 1 = Keypair 1
User 1 + App 2 = Keypair 2

This can be used by the developer to encrypt data, without requiring any custody of the encryption key.


User-to-App

User-to-App is an schema that allows both the user and the app to decrypt messages.

The below snippet shows how to encrypt and decrypt a message with the user encryption key:

const ECIES = require('electrum-ecies');
const { HandCashConnect } = require('@handcash/handcash-connect');
const accessKey = '';
const handcashConnect = new HandCashConnect({ 
   appId: '<app-id>', 
   appSecret: '<secret>',
});

(async () => {
   const cloudAccount = handcashConnect.getAccountFromAuthToken(accessKey);
   const { publicKey } = await cloudAccount.profile.getEncryptionKeypair();
   const { privateKey } = await cloudAccount.profile.getEncryptionKeypair();
   const encryption = ECIES.encrypt('Hello', publicKey);
   const decryptedResult = ECIES.decrypt(encryption, privateKey);
   console.log(decryptedResult.toString());
})();
Hello

Did this page help you?