Encrypt/Decrypt data in Business Central

Hi all,

I am trying to encrypt/decrypt data in business central. Data is encrypted successfully but when i try to decrypt the same data it says “Unable to decrypt data. The data was encrypted using a different key”.

Encryption Procedure
procedure Encrypt(EncryptPass: Text[250]): Text

begin
    IF CU_EncryptionManagement.IsEncryptionEnabled THEN BEGIN
        EncryptPass := COPYSTR(CU_EncryptionManagement.Encrypt(EncryptPass), 1, 249);
        exit(EncryptPass);
    END;
end;

Decryption Procedure
procedure Decrypt(DecryptPass: Text[250]): Text
begin
IF CU_EncryptionManagement.IsEncryptionEnabled THEN BEGIN
DecryptPass := CU_EncryptionManagement.Decrypt(DecryptPass);
exit(DecryptPass);
END;
end;

Thanks in advance