// NOTE: this method can work with ANY configured (OID in machine.config)
        // HashAlgorithm descendant
        public byte[] SignData(Stream inputStream, object halg)
        {
            HashAlgorithm hash = GetHash(halg);

            byte[] toBeSigned = hash.ComputeHash(inputStream);
            return(PKCS1.Sign_v15(this, hash, toBeSigned));
        }
        // NOTE: this method can work with ANY configured (OID in machine.config)
        // HashAlgorithm descendant
        public byte[] SignData(byte[] buffer, int offset, int count, object halg)
        {
            HashAlgorithm hash = GetHash(halg);

            byte[] toBeSigned = hash.ComputeHash(buffer, offset, count);
            return(PKCS1.Sign_v15(this, hash, toBeSigned));
        }
        /// <summary>Computes the hash value of the specified input stream using the specified hash algorithm, and signs the resulting hash value.</summary>
        /// <returns>The <see cref="T:System.Security.Cryptography.RSA" /> signature for the specified data.</returns>
        /// <param name="inputStream">The input data for which to compute the hash. </param>
        /// <param name="halg">The hash algorithm to use to create the hash value. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="halg" /> parameter is null. </exception>
        /// <exception cref="T:System.ArgumentException">The <paramref name="halg" /> parameter is not a valid type. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public byte[] SignData(Stream inputStream, object halg)
        {
            HashAlgorithm hash = this.GetHash(halg);

            byte[] hashValue = hash.ComputeHash(inputStream);
            return(PKCS1.Sign_v15(this, hash, hashValue));
        }
        /// <summary>Computes the signature for the specified hash value by encrypting it with the private key.</summary>
        /// <returns>The <see cref="T:System.Security.Cryptography.RSA" /> signature for the specified hash value.</returns>
        /// <param name="rgbHash">The hash value of the data to be signed. </param>
        /// <param name="str">The hash algorithm identifier (OID) used to create the hash value of the data. </param>
        /// <exception cref="T:System.ArgumentNullException">The <paramref name="rgbHash" /> parameter is null. </exception>
        /// <exception cref="T:System.Security.Cryptography.CryptographicException">The cryptographic service provider (CSP) cannot be acquired.-or- There is no private key. </exception>
        /// <PermissionSet>
        ///   <IPermission class="System.Security.Permissions.KeyContainerPermission, mscorlib, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" version="1" Unrestricted="true" />
        /// </PermissionSet>
        public byte[] SignHash(byte[] rgbHash, string str)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            string        hashName = (str != null) ? this.GetHashNameFromOID(str) : "SHA1";
            HashAlgorithm hash     = HashAlgorithm.Create(hashName);

            return(PKCS1.Sign_v15(this, hash, rgbHash));
        }
        public byte[] SignHash(byte[] rgbHash, string str)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
            // Fx 2.0 defaults to the SHA-1
            string        hashName = (str == null) ? "SHA1" : GetHashNameFromOID(str);
            HashAlgorithm hash     = HashAlgorithm.Create(hashName);

            return(PKCS1.Sign_v15(this, hash, rgbHash));
        }
		public override byte[] CreateSignature (byte[] rgbHash) 
		{
			if (rsa == null) {
				throw new CryptographicUnexpectedOperationException (
					Locale.GetText ("No key pair available."));
			}
			if (hash == null) {
				throw new CryptographicUnexpectedOperationException (
					Locale.GetText ("Missing hash algorithm."));
			}
			if (rgbHash == null)
				throw new ArgumentNullException ("rgbHash");

			return PKCS1.Sign_v15 (rsa, hash, rgbHash);
		}
Пример #7
0
        // LAMESPEC: str is not the hash name but an OID
        // NOTE: this method is LIMITED to SHA1 and MD5 like the MS framework 1.0
        // and 1.1 because there's no method to get a hash algorithm from an OID.
        // However there's no such limit when using the [De]Formatter class.
        public byte[] SignHash(byte[] rgbHash, string str)
        {
            if (rgbHash == null)
            {
                throw new ArgumentNullException("rgbHash");
            }
#if NET_2_0
            // Fx 2.0 defaults to the SHA-1
            string hashName = (str == null) ? "SHA1" : GetHashNameFromOID(str);
#else
            if (str == null)
            {
                throw new CryptographicException(Locale.GetText("No OID specified"));
            }
            string hashName = GetHashNameFromOID(str);
#endif
            HashAlgorithm hash = HashAlgorithm.Create(hashName);
            return(PKCS1.Sign_v15(this, hash, rgbHash));
        }
 byte[] SignHash(byte[] rgbHash, int calgHash)
 {
     return(PKCS1.Sign_v15(this, InternalHashToHashAlgorithm(calgHash), rgbHash));
 }