Beispiel #1
0
 public void ComputeSignature(CmsSigner signer, bool silent)
 {
     if (signer == null)
     {
         throw new ArgumentNullException("signer");
     }
     if (this.ContentInfo.Content.Length == 0)
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Cms_Sign_Empty_Content"));
     }
     if (SubjectIdentifierType.NoSignature == signer.SignerIdentifierType)
     {
         if (this.m_safeCryptMsgHandle != null && !this.m_safeCryptMsgHandle.IsInvalid)
         {
             throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Cms_Sign_No_Signature_First_Signer"));
         }
         this.Sign(signer, silent);
     }
     else
     {
         if (signer.Certificate == null)
         {
             if (silent)
             {
                 throw new InvalidOperationException(SecurityResources.GetResourceString("Cryptography_Cms_RecipientCertificateNotFound"));
             }
             signer.Certificate = PkcsUtils.SelectSignerCertificate();
         }
         if (!signer.Certificate.HasPrivateKey)
         {
             throw new CryptographicException(-2146893811);
         }
         CspParameters parameters = new CspParameters();
         if (!X509Utils.GetPrivateKeyInfo(X509Utils.GetCertContext(signer.Certificate), ref parameters))
         {
             throw new CryptographicException(SignedCms.SafeGetLastWin32Error());
         }
         KeyContainerPermission            containerPermission = new KeyContainerPermission(KeyContainerPermissionFlags.NoFlags);
         KeyContainerPermissionAccessEntry accessEntry         = new KeyContainerPermissionAccessEntry(parameters, KeyContainerPermissionFlags.Open | KeyContainerPermissionFlags.Sign);
         containerPermission.AccessEntries.Add(accessEntry);
         containerPermission.Demand();
         if (this.m_safeCryptMsgHandle == null || this.m_safeCryptMsgHandle.IsInvalid)
         {
             this.Sign(signer, silent);
         }
         else
         {
             this.CoSign(signer, silent);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// The <see cref="M:System.Security.Cryptography.Pkcs.SignerInfo.ComputeCounterSignature(System.Security.Cryptography.Pkcs.CmsSigner)"/> method creates a countersignature by using the specified signer and adds the signature to the CMS/PKCS #7 message. Countersignatures are restricted to one level.
 /// </summary>
 /// <param name="signer">A <see cref="T:System.Security.Cryptography.Pkcs.CmsSigner"/> object that represents the counter signer.</param><exception cref="T:System.ArgumentNullException">A null reference was passed to a method that does not accept it as a valid argument. </exception><exception cref="T:System.Security.Cryptography.CryptographicException">A cryptographic operation could not be completed.</exception>
 public void ComputeCounterSignature(CmsSigner signer)
 {
     if (this.m_parentSignerInfo != null)
     {
         throw new CryptographicException(-2147483647);
     }
     if (signer == null)
     {
         throw new ArgumentNullException("signer");
     }
     if (signer.Certificate == null)
     {
         signer.Certificate = PkcsUtils.SelectSignerCertificate();
     }
     if (!signer.Certificate.HasPrivateKey)
     {
         throw new CryptographicException(-2146893811);
     }
     this.CounterSign(signer);
 }