当前位置: 首页>>代码示例>>C#>>正文


C# KeyedHashAlgorithm.Clear方法代码示例

本文整理汇总了C#中System.Security.Cryptography.KeyedHashAlgorithm.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# KeyedHashAlgorithm.Clear方法的具体用法?C# KeyedHashAlgorithm.Clear怎么用?C# KeyedHashAlgorithm.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.Cryptography.KeyedHashAlgorithm的用法示例。


在下文中一共展示了KeyedHashAlgorithm.Clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: HMACSign

        public static string HMACSign(string data, System.Security.SecureString key, KeyedHashAlgorithm algorithm)
#endif
        {
#if UNITY
            if (String.IsNullOrEmpty(key))
#else
            if (null == key)
#endif
            {
                throw new ArgumentNullException("key", "The AWS Secret Access Key specified is NULL!");
            }

            if (String.IsNullOrEmpty(data))
            {
                throw new ArgumentNullException("data", "Please specify data to sign.");
            }

            if (null == algorithm)
            {
                throw new ArgumentNullException("algorithm", "Please specify a KeyedHashAlgorithm to use.");
            }
#if UNITY
            try
            {
                algorithm.Key = Encoding.UTF8.GetBytes(key);
                return Convert.ToBase64String(algorithm.ComputeHash(
                    Encoding.UTF8.GetBytes(data.ToCharArray()))
                    );
            }
            finally
            {
                algorithm.Clear();
            }
#else
            // pointer to hold unmanaged reference to SecureString instance
            IntPtr bstr = IntPtr.Zero;
            char[] charArray = new char[key.Length];
            try
            {
                // Marshal SecureString into byte array
                bstr = Marshal.SecureStringToBSTR(key);
                Marshal.Copy(bstr, charArray, 0, charArray.Length);
                algorithm.Key = Encoding.UTF8.GetBytes(charArray);
                return Convert.ToBase64String(algorithm.ComputeHash(
                    Encoding.UTF8.GetBytes(data.ToCharArray()))
                    );
            }
            finally
            {
                // Make sure that the clear text data is zeroed out
                Marshal.ZeroFreeBSTR(bstr);
                algorithm.Clear();
                Array.Clear(charArray, 0, charArray.Length);
            }
#endif
        }
开发者ID:GoCarrot,项目名称:carrot-net,代码行数:56,代码来源:AWSSDKUtils.cs

示例2: HMACSign

        /// <summary>
        /// Computes RFC 2104-compliant HMAC signature
        /// </summary>
        /// <param name="data">The data to be signed</param>
        /// <param name="key">The secret signing key</param>
        /// <param name="algorithm">The algorithm to sign the data with</param>
        /// <exception cref="T:System.ArgumentNullException"/>
        /// <returns>A string representing the HMAC signature</returns>
        public static string HMACSign(byte[] data, string key, KeyedHashAlgorithm algorithm)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException("key", "Please specify a Secret Signing Key.");
            }

            if (data == null || data.Length == 0)
            {
                throw new ArgumentNullException("data", "Please specify data to sign.");
            }

            if (null == algorithm)
            {
                throw new ArgumentNullException("algorithm", "Please specify a KeyedHashAlgorithm to use.");
            }

            try
            {
                algorithm.Key = Encoding.UTF8.GetBytes(key);
                byte[] bytes = algorithm.ComputeHash(data);
                return Convert.ToBase64String(bytes);
            }
            finally
            {
                algorithm.Clear();
            }
        }
开发者ID:grandcloud,项目名称:sndacs-csharp,代码行数:36,代码来源:CSSDKUtils.cs

示例3: HMACSign

 public static string HMACSign(string data, SecureString key, KeyedHashAlgorithm algorithm)
 {
     string str;
     if (key == null)
     {
         throw new ArgumentNullException("key", "Please specify a Secret Signing Key.");
     }
     if (string.IsNullOrEmpty(data))
     {
         throw new ArgumentNullException("data", "Please specify data to sign.");
     }
     if (algorithm == null)
     {
         throw new ArgumentNullException("algorithm", "Please specify a KeyedHashAlgorithm to use.");
     }
     IntPtr zero = IntPtr.Zero;
     char[] destination = new char[key.Length];
     try
     {
         zero = Marshal.SecureStringToBSTR(key);
         Marshal.Copy(zero, destination, 0, destination.Length);
         algorithm.Key = Encoding.UTF8.GetBytes(destination);
         str = Convert.ToBase64String(algorithm.ComputeHash(Encoding.UTF8.GetBytes(data.ToCharArray())));
     }
     finally
     {
         Marshal.ZeroFreeBSTR(zero);
         algorithm.Clear();
         Array.Clear(destination, 0, destination.Length);
     }
     return str;
 }
开发者ID:pusp,项目名称:o2platform,代码行数:32,代码来源:AWSSDKUtils.cs


注:本文中的System.Security.Cryptography.KeyedHashAlgorithm.Clear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。