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

Are you using “Cryptography Management” Codeunit?
As far as I know you can not decrypt it. So you shouldn´t save the value this way if you need it later.
This method is for “checking”, as if it were a password. When the password is entered again you can encrypt it and verify that the encrypted value is the same as the previous one. That is, verify between encrypted values.

I haven´t tried it so I might be wrong.