title: SignedCms ComputeSignature throw CryptographicException "The parameter is incorrect."
body: <p>I try sign pdf using <a href="http://www.debenu.com/kb/advanced-options-signing-pdf-files/" rel="nofollow noreferrer">http://www.debenu.com/kb/advanced-options-signing-pdf-files/</a></p>
  
  <p>But it throw exception when call </p>
  
  <pre><code>// Sign the file data (generates an SHA-1 hash and
  // signs that hash)
  byte[] enc = SignData(fileData, cert); //throw exception
  </code></pre>
  
  <p>Here is my SignData function</p>
  
  <pre><code>    private static byte[] SignData(byte[] inputData, X509Certificate2 cert)
      {
          // Create an SHA-1 hash of the file data
          SHA1 sha = new SHA1CryptoServiceProvider();
          byte[] sha1Result = sha.ComputeHash(inputData);
  
          CmsSigner cmsSigner = new CmsSigner(cert);
          cmsSigner.IncludeOption = X509IncludeOption.WholeChain;
          cmsSigner.DigestAlgorithm = new Oid("SHA1");
  
          // Sign the hash using the certificate
          // This could be changed to use a hardware device (eg. smartcard)
          ContentInfo content = new ContentInfo(sha1Result);
          SignedCms signedCms = new SignedCms(SubjectIdentifierType.IssuerAndSerialNumber, content, true);
          signedCms.ComputeSignature(cmsSigner, false); //throw "The parameter is incorrect." 
          return signedCms.Encode();
      }
  </code></pre>
  
  <p>It is Ok when get testSig</p>
  
  <pre><code>    byte[] randomData = new byte[1];
      randomData[0] = 123;
      byte[] testSig = SignData(randomData, cert);
  </code></pre>
  
  <p>EDIT
  This error throw when I use cert from usb token. If I choose other cert has private key it not throw error</p>