Posts

Showing posts from March, 2024

Node Js Private Key And Public Key Encryption and Decryption

    const crypto = require (' crypto ');     // Generate RSA key pair for personal decryption     const MyKey = crypto . generateKeyPairSync (' rsa ', {         modulusLength: 2048 ,         publicKeyEncoding: {             type: ' spki ',             format: ' pem '         },         privateKeyEncoding: {             type: ' pkcs8 ',             format: ' pem '         }     });     // Function to encrypt a message using user's public key     function encryptMessage ( message , publicKey ) {         let encryptMsg ;         try {             encryptMsg = crypto . publicEncrypt ( publicKey , Buffer . from ( message )). toString...