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
Kanagaraj Arjunan 11Kanagaraj Arjunan 11 

Input length must be multiple of 16 when decrypting with padded cipher in salesforce

Hi All

I am trying to decrypt an attachment. while when i excecute the code i am receiving the error like "Input length must be multiple of 16 when decrypting with padded cipher in salesforce" below is my code.

global with sharing class decryptAttachment {
   
    webservice static string decryptAttachmentfile(Id caseIds) {
        c Document d = new Document();
        d.FolderId = UserInfo.getUserId();
        Attachment a = [SELECT Id, Name,ParentId,Body,ContentType FROM Attachment WHERE ParentId =:caseparentIds];
        d.ContentType = a.contentType;
        EncryptionKey__c keySetting = EncryptionKey__c.getOrgDefaults();
        Blob aesKey = EncodingUtil.base64Decode(keySetting.aeskey__c);
        d.Body = Crypto.decryptWithManagedIV('AES256', aesKey, a.Body);
        d.Name = a.Name;
        insert d;
        return d.id;
    }
  }