function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
rupesh ranjanrupesh ranjan 

Encryption are not working plss Help its urgent

Encryption are not working plss Help its urgent

 
public String to{get; set;}
    Blob data6 = Blob.valueOf(to);
   Blob encryptedData6 = Crypto.encryptWithManagedIV('AES256', cryptoKey, data6 );
   public    String b64Data6 = EncodingUtil.base64Encode(encryptedData6);
   public String too= EncodingUtil.urlEncode(b64Data6, 'UTF-8');

 
Sunil MadanaSunil Madana
Hi rupesh, do u have "cryptoKey" variable already declared? If not below is the code.
public String to{get; set;}
Blob data6 = Blob.valueOf(to);
Blob cryptoKey = Crypto.generateAesKey(256);
Blob encryptedData6 = Crypto.encryptWithManagedIV('AES256', cryptoKey, data6 );
public String b64Data6 = EncodingUtil.base64Encode(encryptedData6);
public String too= EncodingUtil.urlEncode(b64Data6, 'UTF-8');
As per the documentation, you need to generate Aes key and pass it to encryptWithManagedIV method. Refer to below URL:
https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_crypto.htm (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_restful_crypto.htm" target="_blank)

Let me know if the above solution works for you. Thanks, Sunil.
rupesh ranjanrupesh ranjan
Yes i already have cryptoKey but still not working