Exemple #1
0
        public async ValueTask <byte[]?> DB(byte[]?value, string?secondaryPassword)
        {
            if (value == null)
            {
                return(value);
            }
            if (value.Length == 0)
            {
                return(value);
            }
            if (value.Length <= sizeof(int))
            {
                return(null);
            }

            var d_type = (EncryptionMode)BitConverter.ToInt32(value, 0);

            switch (d_type)
            {
            case EncryptionMode.EmbeddedAes:
                var value_1   = UnConcat(value);
                var value_1_r = ea.DB(value_1);
                return(value_1_r);

            case EncryptionMode.EmbeddedAesWithLocal:
                var value_2       = UnConcat(value);
                var value_2_local = await local.DB(value_2);

                var value_2_r = ea.DB(value_2_local);
                return(value_2_r);

            case EncryptionMode.EmbeddedAesWithSecondaryPassword:
                if (string.IsNullOrWhiteSpace(secondaryPassword))
                {
                    return(null);
                }
                var value_3    = UnConcat(value);
                var value_3_sp = sp.DB(value_3, secondaryPassword);
                var value_3_r  = ea.DB(value_3_sp);
                return(value_3_r);

            case EncryptionMode.EmbeddedAesWithSecondaryPasswordWithLocal:
                if (string.IsNullOrWhiteSpace(secondaryPassword))
                {
                    return(null);
                }
                var value_4       = UnConcat(value);
                var value_4_local = await local.DB(value_4);

                var value_4_sp = sp.DB(value_4_local, secondaryPassword);
                var value_4_r  = ea.DB(value_4_sp);
                return(value_4_r);

            default:
                return(null);
            }
        }
Exemple #2
0
        public async ValueTask <(byte[]? content, DResultCode resultCode)> DB2(byte[]?value, string?secondaryPassword)
        {
            if (value == null || value.Length == 0)
            {
                return(value, DResultCode.Success);
            }
            if (value.Length <= sizeof(int))
            {
                return(null, DResultCode.IncorrectValueFail);
            }

            var d_type = (EncryptionMode)BitConverter.ToInt32(value, 0);

            switch (d_type)
            {
            case EncryptionMode.EmbeddedAes:
                var value_1   = UnConcat(value);
                var value_1_r = ea.DB(value_1);
                return(value_1_r, value_1_r == null ?
                       DResultCode.EmbeddedAesFail : DResultCode.Success);

            case EncryptionMode.EmbeddedAesWithLocal:
                var value_2       = UnConcat(value);
                var value_2_local = await local.DB(value_2);

                if (value_2_local == null)
                {
                    return(null, DResultCode.LocalFail);
                }
                var value_2_r = ea.DB(value_2_local);
                return(value_2_r, value_2_r == null ?
                       DResultCode.EmbeddedAesFail : DResultCode.Success);

            case EncryptionMode.EmbeddedAesWithSecondaryPassword:
                if (string.IsNullOrWhiteSpace(secondaryPassword))
                {
                    return(null, DResultCode.SecondaryPasswordFail);
                }
                var value_3    = UnConcat(value);
                var value_3_sp = sp.DB(value_3, secondaryPassword);
                if (value_3_sp == null)
                {
                    return(null, DResultCode.SecondaryPasswordFail);
                }
                var value_3_r = ea.DB(value_3_sp);
                return(value_3_r, value_3_r == null ?
                       DResultCode.EmbeddedAesFail : DResultCode.Success);

            case EncryptionMode.EmbeddedAesWithSecondaryPasswordWithLocal:
                if (string.IsNullOrWhiteSpace(secondaryPassword))
                {
                    return(null, DResultCode.SecondaryPasswordFail);
                }
                var value_4       = UnConcat(value);
                var value_4_local = await local.DB(value_4);

                if (value_4_local == null)
                {
                    return(null, DResultCode.LocalFail);
                }
                var value_4_sp = sp.DB(value_4_local, secondaryPassword);
                if (value_4_sp == null)
                {
                    return(null, DResultCode.SecondaryPasswordFail);
                }
                var value_4_r = ea.DB(value_4_sp);
                return(value_4_r, value_4_r == null ?
                       DResultCode.EmbeddedAesFail : DResultCode.Success);

            default:
                return(null, DResultCode.IncorrectValueFail);
            }
        }