emrekizildas / EntityFrameworkCore.EncryptColumn

Encrypt & Decrypt your databases columns using EntityFramework Core.
MIT License
87 stars 40 forks source link

5.0.6 data loss bug #12

Closed gala-s closed 2 years ago

gala-s commented 2 years ago

The current release writes an empty string to the database instead of the encrypted value. I was able to verify this using the example project, after upgrading that project to EncryptColumn 5.0.6.

Looking at the repository history, it looks like the issue may have been resolved here back in August, but an updated NuGet package wasn't published afterward.

gala-s commented 2 years ago

I did some testing with previous versions and 3.1 is also affected, it looks like the initial release is the only one that writes the encrypted value to the DB.

jsucupira commented 2 years ago

For me the only package that worked was v1. the other two (3 and 5) were saying blank data.

oguzhankahyaoglu commented 2 years ago

The problem is relevant with "Initialize.Key" methods. He used static constructor, passed "Key" value between classes.

Thus, manipulating Initialize.Key method is the corrupted one. I solved the issue by registering GenerateEncryptionProvider as singleton with Key argument and use registered DI instance as follows:

namespace EntityFrameworkCore.EncryptColumn.Util
{
    public class GenerateEncryptionProvider : IEncryptionProvider
    {
        private readonly string _key;

        public GenerateEncryptionProvider(string key)
        {
            _key = key;
        }
marcwlux commented 2 years ago

You need to compile the project from source. It works fine. The nuget-package doesn't work.