apex.runtime.impl.ExecutionException: pad block corrupted

if (req.headers.get('username') != null&&req.headers.get('password')!=null && Authorization.decrypt(req.headers.get('username'),req.headers.get('password'){
        for(Visit vf : VisitsDataList){

                } else {
                    actionMapVisitIds.put(vf.ActionName, new List<String{vf.Id});

Test Class

JSONGenerator gen = JSON.createGenerator(true);     
        gen.writeObjectField('listVisitsData', visitList);

       String json =gen.getAsString();  
       system.debug('@@@@@ '+json);    

    RestRequest req = new RestRequest(); 
    RestResponse res = new RestResponse();

    String username ='EmpApp';
    String password ='2ZnGZayPcs0t+yfu5rciKNGlO7Ogx4QJ0puSu7+I9e6ykZfJL4NGrMrogBxBxrK3';

    req.requestURI = 'https://cs5.salesforce.com/services/apexrest/getVisitDetails/';  
    req.httpMethod = 'POST';  
    req.addHeader('Content-Type', 'application/json');      
    req.addHeader('username', username);
    req.addHeader('password', password); 

    req.requestBody = Blob.valueof(json);
    RestContext.request = req;
    RestContext.response = res;    

  • req.requestBody = Blob.valueof(json); No variable called json in your code? Feb 19, 2019 at 12:09
  • @nube i added Json string
    – user63974
    Feb 19, 2019 at 12:16
  • Please edit your question to make clear what the issue is with which you'd like assistance. If you have an error, include it verbatim with line number. Right now, all we can see is that you seem to have written the code to do what your question's title says already.
    – David Reed
    Feb 19, 2019 at 12:32
  • apex.runtime.impl.ExecutionException: pad block corrupted getting this Error
    – user63974
    Feb 19, 2019 at 12:59
  • Please edit your question to include the specific error message and line. Comments are not for providing extra information.
    – David Reed
    Feb 19, 2019 at 13:05

1 Answer 1


apex.runtime.impl.ExecutionException: pad block corrupted

This message means that your ciphertext (the value of username, apparently) is corrupted or is not valid ciphertext. I discussed this at greater length in a previous answer; the short summary is that your ciphertext may have had a character altered or removed, or has such a mutation performed in your decryption code.

It looks like you are providing a base64-encoded cryptographic key in password and an encrypted value in username. However, the value you're showing in username in your unit test is in plaintext, which won't be able to be decrypted successfully.

However your Authorization class is implemented, you'll need to generate a real, valid ciphertext and password pair to populate in your unit test.

You must log in to answer this question.