ALAppExtensions icon indicating copy to clipboard operation
ALAppExtensions copied to clipboard

Passwords encrypted in C/AL with Rfc2898DeriveBytes

Open angela2389 opened this issue 7 years ago • 11 comments

We are currently using Rfc2898DeriveBytes in C/AL to encrypt passwords/data (in combination with other encryption). In AL this functionality is missing, therefore causing that we cannot check if passwords are correct when users fill in the password to access data files. We cannot decrypt the passwords in C/AL either to convert them to a different type in AL. Users will therefore be unable to access encrypted data files. Thereby, we would like to continue using Rfc2898DeriveBytes to properly secure our files.

Can you please add the Rfc2898DeriveBytes functionality in a Codeunit we can access?

angela2389 avatar Apr 09 '19 10:04 angela2389

We use external web service (similar to Azure functions) for such tasks, which isn’t ideal, but it works.

yrest avatar Apr 09 '19 11:04 yrest

Yes, that would be a last resort indeed, but far from ideal.

There is already a Codeunit called "Encryption Management", so it would be great if it can be added there.

angela2389 avatar Apr 09 '19 12:04 angela2389

Hi @angela2389, I will transfer you to the extensions repository which can offer more insights and hopefully help you.

ghost avatar Apr 09 '19 13:04 ghost

Hi @angela2389, Thanks for your proposal. Looks like a valid one, but it is also a new requirement. When it comes to such proposals, we also need to evaluate importance for all partners. We will do triage this week and inform you about the decision.

PredragMaricic avatar Jun 24 '19 08:06 PredragMaricic

Hi @angela2389,,

We created and opensourced Encryption Management module, so you might want to take a look and suggest the code to provide support for Rfc2898DeriveBytes. Then we can review it and add it to the module if possible. https://github.com/microsoft/ALAppExtensions/tree/master/Modules/Cryptography%20Management

PredragMaricic avatar Jun 26 '19 05:06 PredragMaricic

Hi @PredragMaricic ,

Is it possible to implement it like this?

   procedure FuncCreateHashWithRfc2898DeriveBytes(Password: Text; InputText: Text; DivideHashBy: Integer ) Hash: Text
    var
        ByteArray: DotNet Array; // System.Array
        Convert: DotNet Convert; // System.Convert
        Encoding: DotNet Encoding; // System.Text.Encoding
        Rfc2898DeriveBytes: DotNet Rfc2898DeriveBytes; //System.Security.Cryptography.Rfc2898DeriveBytes
        SHA1Managed: DotNet SHA1Managed; // System.Security.Cryptography.SHA1Managed
    begin
        if InputText = '' then
          exit;

        Rfc2898DeriveBytes := Rfc2898DeriveBytes.Rfc2898DeriveBytes(Password,Encoding.ASCII.GetBytes(InputText)); 
        SHA1Managed := SHA1Managed.SHA1Managed;
        ByteArray := SHA1Managed.ComputeHash(Rfc2898DeriveBytes.GetBytes(SHA1Managed.HashSize / DivideHashBy));              
        Hash := Convert.ToBase64String(ByteArray);    

        Clear(ByteArray);                              
        Clear(SHA1Managed);
        Clear(Rfc2898DeriveBytes);
    end;

Additionally, we use some more encrypt methods, for different purposes as above (above is prio), such as System.Security.Cryptography.RijndaelManaged and System.Security.Cryptography.DESCryptoServiceProvider. However, as there are so many options how to use these methods, I'm not sure if I will be able to make general functions for all to use... Is it possible to add these as Datatypes in AL?

Can we discuss this further by e-mail?

angela2389 avatar Jun 27 '19 09:06 angela2389

@JesperSchulz - can you finally address this ask? Or close this request?

AlexanderYakunin avatar Feb 05 '20 07:02 AlexanderYakunin

Before I close this issue... @angela2389, did you discuss this further with @PredragMaricic? In case you'd like to contribute to the Cryptography module, here's an example of how one of our partners added Rijndael capabilities! Feel free to follow his lead and add more :-)

JesperSchulz avatar Feb 06 '20 15:02 JesperSchulz

Hi @angela2389, echoing what Jesper is saying. Please check if the newly added Rijndael Cryptography can suit your needs. Otherwise if you'd like to contribute please make a PR and we will try to incorporate it into the Cryptography Management module. :)

PaulIvan avatar Feb 07 '20 10:02 PaulIvan

Hoi @JesperSchulz and @PaulIvan,

No I haven't heard from PredragMaricic. The Rijndael Cryptography doesn't suit our needs. I will try make a Pull Request today.

angela2389 avatar Feb 07 '20 10:02 angela2389

Looking forward to it! I will close this issue and will be waiting to process your PR :-)

JesperSchulz avatar Feb 07 '20 14:02 JesperSchulz