Exemplo n.º 1
0
        internal static string ComputeHash(string value)
        {
            if (s_useEncryption)
            {
                EnsureConfig();
                HashAlgorithm algorithm = (HashAlgorithm)s_oHashAlgoStack.Pop();
                if (null == algorithm)
                {
                    algorithm = NewHashAlgorithm();
                }

                byte[]   encrypted;
                byte[]   bytes  = new byte[ADP.CharSize * value.Length];
                GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
                try {
                    System.Text.Encoding.Unicode.GetBytes(value, 0, value.Length, bytes, 0);
                    encrypted = algorithm.ComputeHash(bytes);
                }
                finally {
                    Array.Clear(bytes, 0, bytes.Length);
                    if (handle.IsAllocated)
                    {
                        handle.Free();
                    }
                }
                s_oHashAlgoStack.Push(algorithm);
                return(System.Text.Encoding.Unicode.GetString(encrypted, 0, encrypted.Length));
            }
            return(value);
        }
Exemplo n.º 2
0
        private static ICryptoTransform GetCryptoTransform(bool fEncrypt)
        {
            InterlockedStack st = (fEncrypt ? s_oEncryptorStack : s_oDecryptorStack);
            ICryptoTransform ct = (st.Pop() as ICryptoTransform);

            if (null == ct)
            {
                ct = NewCryptTransform(fEncrypt);
            }
            return(ct);
        }