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
mariappangomathirajmariappangomathiraj 

Encoding and decoding in Apex

Is anyone help to get the output for Below code? Some Encoding and decoding problem in my data.

 

My output::

 

/SMS/Homepage

 

My code:

String url = 'https://developer-edition.na9.force.com/MMMS/sitelogin?goto=%2Fapex%2FUnauthorized%3FstartURL%3D%252FSMS%252FHomepage';
System.debug(':::::::::url::::'+url);
url = url.substringAfter('startURL');
String encoded = EncodingUtil.urlEncode(url, 'UTF-8');
System.debug(':::::::::encodedData::::::::::'+encoded);
String decoded = EncodingUtil.urlDecode(encoded, 'UTF-8');
System.debug(':::::::::decodeddata::::::::::'+decoded);


::::::::url::::https://developer-edition.na9.force.com/MMMS/sitelogin?goto=%2Fapex%2FUnauthorized%3FstartURL%3D%252FSMS%252FHomepage
:::::::::encodedData::::::::::%253D%25252FSMS%25252FHomepage
::::::::decodeddata::::::::::%3D%252FSMS%252FHomepage

Ankush SamudralaAnkush Samudrala

Yo should follow the folowing pattern:

 

Encryption: Start Field > Blob.valueOf > Encrypt > encode > End Field

 

Decryption: End Field > decode > Decrypt > Blob.toString > Start Field

 

For example:

 

Blob cryptoKey = Crypto.generateAesKey(256);

// Generate the data to be encrypted.  
    
Blob data = Blob.valueOf('Test data to encrypted');

// Encrypt the data and have Salesforce.com generate the initialization vector   
    
Blob encryptedData = Crypto.encryptWithManagedIV('AES256', cryptoKey, data);

// Decrypt the data  
    
Blob decryptedData = Crypto.decryptWithManagedIV('AES256', cryptoKey, encryptedData);
mariappangomathirajmariappangomathiraj

Its not working.I am getting the same output.Its not encrypted.Its didn't remove the %2F