Esempio n. 1
0
		/// <summary>
		/// Populates this CMS blob with the data from signing a code directory
		/// </summary>
		public void SignCodeDirectory(X509Certificate2 SigningCert, DateTime SigningTime, CodeDirectoryBlob CodeDirectory)
		{
			// Create a signer
			CmsSigner Signer = new CmsSigner(SigningCert);
			Signer.IncludeOption = X509IncludeOption.WholeChain;
			Signer.SignerIdentifierType = SubjectIdentifierType.IssuerAndSerialNumber;
			Signer.DigestAlgorithm = new Oid(CryptoConfig.MapNameToOID("SHA1"), "SHA1");

			// A Pkcs9ContentType and Pkcs9MessageDigest will automatically be added, and it fails to
			// compute a signature if they are added manually, so only the signing time needs to be added
			Signer.SignedAttributes.Add(new Pkcs9SigningTime(SigningTime));

			// Sign the data (in a detached manner, so only the digest of the CodeDirectory is
			// stored in the CMS blob and not the whole CodeDirectory blob)
			bool bDetached = true;
			bool bSilent = true;
			ContentInfo CodeDirContentInfo = new ContentInfo(CodeDirectory.GetBlobBytes());
			SignedCms CMS = new SignedCms(CodeDirContentInfo, bDetached);
			CMS.ComputeSignature(Signer, bSilent);

			MyData = CMS.Encode();
		}