+ Start a Discussion

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::




My code:

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


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);

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