Exemple #1
0
        public static IEncryptor GetEncryptor(DisplayMonkeyEntities _db)    // 1.4.0
        {
            EncryptionMethods encryptionMethod = EncryptionMethods.RsaContainer;
            IEncryptor        encryptor        = null;
            Setting           s = Setting.GetSetting(_db, Keys.EncryptionMethod);

            if (s != null)
            {
                encryptionMethod = (EncryptionMethods)s.IntValuePositive;
            }

            switch (encryptionMethod)
            {
            case EncryptionMethods.RsaContainer:
                encryptor = new RsaEncryptor();
                break;

            case EncryptionMethods.Aes:
                encryptor = new AesEncryptor();

                s = Setting.GetSetting(_db, Keys.EncryptionIV);
                if (s != null && s.RawValue != null)
                {
                    (encryptor as AesEncryptor).IV = s.RawValue;
                }
                else
                {
                    Setting.SaveSetting(_db, Keys.EncryptionIV, (encryptor as AesEncryptor).IV);
                }

                s = Setting.GetSetting(_db, Keys.EncryptionKey);
                if (s != null && s.RawValue != null)
                {
                    (encryptor as AesEncryptor).Key = s.RawValue;
                }
                else
                {
                    Setting.SaveSetting(_db, Keys.EncryptionKey, (encryptor as AesEncryptor).Key);
                }

                break;
            }

            return(encryptor);
        }