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.

  • 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 3 years, 6 months ago by  Marziya.
    • This reply was modified 3 years, 6 months ago by  Marziya.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos