System.Security.Cryptography.DSASignatureFormatter.SetHashAlgorithm C# (CSharp) Method

SetHashAlgorithm() public method

public SetHashAlgorithm ( string strName ) : void
strName string
return void
		public override void SetHashAlgorithm (string strName)
		{
			if (strName == null)
				throw new ArgumentNullException ("strName");

			try {
				// just to test, we don't need the object
				SHA1.Create (strName);
			}
			catch (InvalidCastException) {
				throw new CryptographicUnexpectedOperationException (
					Locale.GetText ("DSA requires SHA1"));
			}
		}

Usage Example

        /// <summary>
        /// 数字签名处理.
        /// </summary>
        /// <param name="HashToSign"></param>
        /// <param name="DSAKeyInfo"></param>
        /// <param name="HashAlg"></param>
        /// <returns></returns>
        public static byte[] DSASignHash(byte[] HashToSign, DSAParameters DSAKeyInfo, string HashAlg)
        {
            try
            {
                //Create a new instance of DSACryptoServiceProvider.
                DSACryptoServiceProvider DSA = new DSACryptoServiceProvider();

                //Import the key information.
                DSA.ImportParameters(DSAKeyInfo);

                //Create an DSASignatureFormatter object and pass it the
                //DSACryptoServiceProvider to transfer the private key.
                DSASignatureFormatter DSAFormatter = new DSASignatureFormatter(DSA);

                //Set the hash algorithm to the passed value.
                DSAFormatter.SetHashAlgorithm(HashAlg);

                //Create a signature for HashValue and return it.
                return DSAFormatter.CreateSignature(HashToSign);
            }
            catch (CryptographicException e)
            {
                Console.WriteLine(e.Message);

                return null;
            }
        }
All Usage Examples Of System.Security.Cryptography.DSASignatureFormatter::SetHashAlgorithm