public void Constructor_SecurityElement_Empty () 
	{
		// (empty) SecurityElement constructor
		SecurityElement se = new SecurityElement ("xml");
		SignatureDescription sig = new SignatureDescription (se);
		AssertNotNull ("SignatureDescription(SecurityElement)", sig);
	}
	public void SetUp () 
	{
		sig = new SignatureDescription();
		// key generation is VERY long so one time is enough
		if (dsa == null)
			dsa = DSA.Create ();
		if (rsa == null)
			rsa = RSA.Create ();
	}
	public void Constructor_SecurityElement_RSA ()
	{
		SecurityElement se = new SecurityElement ("RSASignature");
		se.AddChild (new SecurityElement ("Key", "System.Security.Cryptography.RSACryptoServiceProvider"));
		se.AddChild (new SecurityElement ("Digest", "System.Security.Cryptography.SHA1CryptoServiceProvider"));
		se.AddChild (new SecurityElement ("Formatter", "System.Security.Cryptography.RSAPKCS1SignatureFormatter"));
		se.AddChild (new SecurityElement ("Deformatter", "System.Security.Cryptography.RSAPKCS1SignatureDeformatter"));

		SignatureDescription sig = new SignatureDescription (se);
		Assert.AreEqual ("System.Security.Cryptography.RSACryptoServiceProvider", sig.KeyAlgorithm);
		Assert.AreEqual ("System.Security.Cryptography.SHA1CryptoServiceProvider", sig.DigestAlgorithm);
		Assert.AreEqual ("System.Security.Cryptography.RSAPKCS1SignatureFormatter", sig.FormatterAlgorithm);
		Assert.AreEqual ("System.Security.Cryptography.RSAPKCS1SignatureDeformatter", sig.DeformatterAlgorithm);
	}
예제 #4
0
        void ComputeHash(out AsymmetricAlgorithm privateKey, out SignatureDescription description, out HashAlgorithm hash)
        {
            privateKey = this.Certificate.PrivateKey;
            description = CryptoConfig.CreateFromName(this.SHA1SignatureName) as SignatureDescription;
            if (description == null)
            {
                throw new CompactSignatureSecurityException(string.Format(
                     CultureInfo.CurrentCulture,
                     "Error creating SignatureDescription from the signature name {0}",
                     this.SHA1SignatureName));
            }

            hash = description.CreateDigest();
            if (hash == null)
            {
                throw new CompactSignatureSecurityException(string.Format(
                    CultureInfo.CurrentCulture,
                    "Error creating HashAlgorithm from the signature name {0}",
                    this.SHA1SignatureName));
            }

            HashStream hashStream = this.TakeHashStream(hash);

            // Create the references
            StringBuilder sb = new StringBuilder();
            if (!String.IsNullOrEmpty(this.InclusivePrefixesList))
            {
                for (int i = 0; i < this.references.Count; i++)
                {
                    sb.Append(string.Format(SignatureProcessor.ExtendedSignatureReferenceWithPrefixes,
                                this.references[i].Id,
                                this.InclusivePrefixesList,
                                Convert.ToBase64String(this.references[i].Digest)));
                }
            }
            else
            {
                for (int i = 0; i < this.references.Count; i++)
                {
                    sb.Append(string.Format(SignatureProcessor.ExtendedSignatureReferenceNoPrefixes,
                                this.references[i].Id,
                                Convert.ToBase64String(this.references[i].Digest)));
                }
            }

            string expandedSignature = string.Format(
                ExpandedSignatureScheleton,
                // Replace the references
                sb.ToString());

            byte[] bytes = Encoding.UTF8.GetBytes(expandedSignature);
            hashStream.Write(bytes, 0, bytes.Length);
            hashStream.FlushHash();
        }
	public void Constructor_Null () 
	{
		// null constructor
		SignatureDescription sig = new SignatureDescription (null);
		// LAMESPEC: Documented as CryptographicException
	}
	public void Constructor_Default () 
	{
		// empty constructor
		SignatureDescription sig = new SignatureDescription ();
	}
	public void Constructor_Default () 
	{
		// empty constructor
		SignatureDescription sig = new SignatureDescription ();
		AssertNotNull ("SignatureDescription()", sig);
	}
 internal static void LogVerifySignedInfo(SignedXml signedXml, AsymmetricAlgorithm key, SignatureDescription signatureDescription, HashAlgorithm hashAlgorithm, AsymmetricSignatureDeformatter asymmetricSignatureDeformatter, byte[] actualHashValue, byte[] signatureValue)
 {
     if (InformationLoggingEnabled)
     {
         string data = string.Format(CultureInfo.InvariantCulture, SecurityResources.GetResourceString("Log_VerifySignedInfoAsymmetric"), new object[] { GetKeyName(key), signatureDescription.GetType().Name, hashAlgorithm.GetType().Name, asymmetricSignatureDeformatter.GetType().Name });
         WriteLine(signedXml, TraceEventType.Information, SignedXmlDebugEvent.VerifySignedInfo, data);
     }
     if (VerboseLoggingEnabled)
     {
         string str2 = string.Format(CultureInfo.InvariantCulture, SecurityResources.GetResourceString("Log_ActualHashValue"), new object[] { FormatBytes(actualHashValue) });
         WriteLine(signedXml, TraceEventType.Verbose, SignedXmlDebugEvent.VerifySignedInfo, str2);
         string str3 = string.Format(CultureInfo.InvariantCulture, SecurityResources.GetResourceString("Log_RawSignatureValue"), new object[] { FormatBytes(signatureValue) });
         WriteLine(signedXml, TraceEventType.Verbose, SignedXmlDebugEvent.VerifySignedInfo, str3);
     }
 }
 internal static void LogSigning(SignedXml signedXml, object key, SignatureDescription signatureDescription, HashAlgorithm hash, AsymmetricSignatureFormatter asymmetricSignatureFormatter)
 {
     if (InformationLoggingEnabled)
     {
         string data = string.Format(CultureInfo.InvariantCulture, SecurityResources.GetResourceString("Log_SigningAsymmetric"), new object[] { GetKeyName(key), signatureDescription.GetType().Name, hash.GetType().Name, asymmetricSignatureFormatter.GetType().Name });
         WriteLine(signedXml, TraceEventType.Information, SignedXmlDebugEvent.Signing, data);
     }
 }