Skip to content

Commit

Permalink
Add Node JS example to Params Encryption section (#336)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doimhneacht authored Sep 24, 2024
1 parent 886b611 commit a9302bf
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion source/advanced_features/params_encryption.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,38 @@ that can be downloaded from `Bouncy Castle Latest Releases`_.
}
public static void main(String[] args) throws Exception {
String email = "encrypted_email@example.com";
String email = "email_to_encrypt@example.com";
System.out.println(encryptParam(email));
}
}
Node.js Example
---------------

.. code-block:: js
const fs = require('fs');
const crypto = require('crypto');
// Read the public key from file
const publicKey = fs.readFileSync('talkable_your_site_slug_public_key.pem', 'utf8');
const encryptData = (data) => {
const encryptedData = crypto.publicEncrypt(
{
key: publicKey,
padding: crypto.constants.RSA_PKCS1_OAEP_PADDING,
oaepHash: 'sha1',
},
Buffer.from(data)
);
return encryptedData.toString('base64');
};
// Example usage
const encryptedEmail = encryptData('email_to_encrypt@example.com');
console.log('Encrypted email:', encryptedEmail);
Front-end Part
--------------

Expand Down

0 comments on commit a9302bf

Please # to comment.