Activity Forums Salesforce® Discussions How to encrypt and decrypt data in Apex ?

  • Anjali

    Member
    October 21, 2020 at 2:15 PM

    we can encrypt and decrypt data in apex by using crypto class.

  • [adinserter block='9']
  • Marziya

    Member
    October 21, 2020 at 2:17 PM

    `//Data to encrypt`
    `Blob data = Blob.valueOf(“’Biswajeet Samal’“);`
    `//Generate an AES key for the encryption. `
    `Blob cryptoValue = Crypto.generateAesKey(“256“);`
    `//Encrypt the data`
    `Blob encryptedData = Crypto.encryptWithManagedIV(“’AES256’“, cryptoValue, data);`
    `//Decrypt the data – the first 16 bytes contain the initialization vector`
    `Blob decryptedData = Crypto.decryptWithManagedIV(“’AES256’“, cryptoValue, encryptedData);`
    `
    `

    • This reply was modified 5 years, 7 months ago by  Marziya.
    • This reply was modified 5 years, 7 months ago by  Marziya.

Log In to reply.