Exemplo n.º 1
0
        protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue)
        {
            long   signHash, valueHash;
            object value;
            string sharedSecret;

            if ((object)obfuscationContext == null)
            {
                throw new ArgumentNullException(nameof(obfuscationContext));
            }

            if ((object)columnSpec == null)
            {
                throw new ArgumentNullException(nameof(columnSpec));
            }

            if ((object)field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if ((object)columnSpec.ObfuscationStrategySpec == null)
            {
                throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec)));
            }

            signHash     = obfuscationContext.GetSignHash(columnValue);
            valueHash    = obfuscationContext.GetValueHash(null, columnValue);
            sharedSecret = ((valueHash <= 0 ? 1 : valueHash) * (signHash % 2 == 0 ? -1 : 1)).ToString("X");

            value = GetCipher(sharedSecret, columnValue);

            return(value);
        }
        protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue)
        {
            long   valueHash;
            object value;
            long   randomSeed;

            if ((object)obfuscationContext == null)
            {
                throw new ArgumentNullException(nameof(obfuscationContext));
            }

            if ((object)columnSpec == null)
            {
                throw new ArgumentNullException(nameof(columnSpec));
            }

            if ((object)field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if ((object)columnSpec.ObfuscationStrategySpec == null)
            {
                throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec)));
            }

            valueHash  = obfuscationContext.GetValueHash(null, columnValue);
            randomSeed = valueHash;

            value = GetShuffle(randomSeed, columnValue);

            return(value);
        }
        protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue)
        {
            long   valueHash;
            object value;
            long   randomSeed;

            if ((object)obfuscationContext == null)
            {
                throw new ArgumentNullException(nameof(obfuscationContext));
            }

            if ((object)columnSpec == null)
            {
                throw new ArgumentNullException(nameof(columnSpec));
            }

            if ((object)field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if ((object)columnSpec.ObfuscationStrategySpec == null)
            {
                throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec)));
            }

            valueHash  = obfuscationContext.GetValueHash(null, field.FieldName);
            randomSeed = valueHash;

            // create a new repeatable yet random-ish math funcion using the random seed, then executes for column value
            value = GetSurrogateKey(randomSeed, columnValue);

            return(value);
        }
        protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue)
        {
            long   signHash, valueHash;
            object value;
            double varianceFactor;

            if ((object)obfuscationContext == null)
            {
                throw new ArgumentNullException(nameof(obfuscationContext));
            }

            if ((object)columnSpec == null)
            {
                throw new ArgumentNullException(nameof(columnSpec));
            }

            if ((object)field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if ((object)columnSpec.ObfuscationStrategySpec == null)
            {
                throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec)));
            }

            signHash       = obfuscationContext.GetSignHash(columnValue);
            valueHash      = obfuscationContext.GetValueHash(columnSpec.ObfuscationStrategySpec.VariancePercentValue, columnValue);
            varianceFactor = ((((valueHash <= 0 ? 1 : valueHash)) * ((signHash % 2 == 0 ? 1.0 : -1.0))) / 100.0);

            value = GetVariance(varianceFactor, columnValue);

            return(value);
        }
Exemplo n.º 5
0
        protected override object CoreGetObfuscatedValue(IObfuscationContext obfuscationContext, IColumnSpec <Spec> columnSpec, IField field, object columnValue)
        {
            Type   valueType;
            string _columnValue;

            long   surrogateKey;
            object surrogateValue;

            IDictionarySpec dictionarySpec;

            if ((object)obfuscationContext == null)
            {
                throw new ArgumentNullException(nameof(obfuscationContext));
            }

            if ((object)columnSpec == null)
            {
                throw new ArgumentNullException(nameof(columnSpec));
            }

            if ((object)field == null)
            {
                throw new ArgumentNullException(nameof(field));
            }

            if ((object)columnSpec.ObfuscationStrategySpec == null)
            {
                throw new InvalidOperationException(string.Format("Specification missing: '{0}'.", nameof(columnSpec.ObfuscationStrategySpec)));
            }

            if ((object)columnValue == null)
            {
                return(null);
            }

            valueType = columnValue.GetType();

            if (valueType != typeof(string))
            {
                return(null);
            }

            _columnValue = (string)columnValue;
            _columnValue = _columnValue.Trim();

            if (SolderFascadeAccessor.DataTypeFascade.IsWhiteSpace(_columnValue))
            {
                return(_columnValue);
            }

            dictionarySpec = columnSpec.ObfuscationStrategySpec.DictionarySpec;

            if ((object)dictionarySpec == null)
            {
                throw new InvalidOperationException(string.Format("Failed to obtain dictionary."));
            }

            if ((dictionarySpec.RecordCount ?? 0L) <= 0L)
            {
                return(null);
            }

            surrogateKey = obfuscationContext.GetValueHash(dictionarySpec.RecordCount, columnValue);

            if (!obfuscationContext.TryGetSurrogateValue(dictionarySpec, surrogateKey, out surrogateValue))
            {
                throw new InvalidOperationException(string.Format("Failed to obtain surrogate value."));
            }

            return(surrogateValue);
        }