title: C# USB eToken signature and validation issue
body: <p>I have an x509 certificate with a public and private key that is stored on a safenet usb token.</p>
  
  <p>I have some data I want to sign.  I need to use the public key of the certificate to verify the signature.</p>
  
  <p>Ultimate code doing the signing with my own self signed certificate:</p>
  
  <pre><code>RSACryptoServiceProvider rsa1 = (RSACryptoServiceProvider)useCertificate.PrivateKey;
  byte[] digitalSignature = rsa1.SignHash(hash, CryptoConfig.MapNameToOID("SHA1"));
  </code></pre>
  
  <p>And the code to verify using the public key of the certificate:</p>
  
  <pre><code>RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)useCertificate.PublicKey.Key;
  Verified = rsa.VerifyHash(hash, CryptoConfig.MapNameToOID("SHA1"), digitalSignature);
  </code></pre>
  
  <p>With the self signed certificate this works fine.  The signature I get back is 256<br>
  Bytes.</p>
  
  <p>With the token using this code to obtain the signature and then verify it, I get only 128 Byte signature and the verify fails:</p>
  
  <pre><code>CspParameters csp = new CspParameters(1, "SafeNet RSA CSP");
  csp.Flags = CspProviderFlags.UseDefaultKeyContainer;
  csp.KeyNumber = (int)KeyNumber.Signature;
  RSACryptoServiceProvider rsa1 = new RSACryptoServiceProvider(csp);
  </code></pre>
  
  <p>Verify code same as above.</p>
  
  <p>I note that the certificate I want to use is the default in the token.  Why am I only getting a 128 Byte signature back instead of 256?  I suspect that is why it won't verify.</p>
  
  <p>Do I need some other parameters and settings in my csp?</p>
  
  <p>Thanks</p>
  
  <p><strong>* Update based on comments *</strong></p>
  
  <p>It's clear that I am using 1024 bits when I specify the csp.keyNumber = (int)KeyNumber.Signature - but this is the only way the token actually returns anything.  Even though the token key size is 2048 bits and the key specification is AT_KEYEXCHANGE.  When I use the exchange keynumber which I think is actually correct, then when I try to compute a signature I am prompted to login, but then I get an exception "The parameter is invalid".   So I need one of 2 things as far as I can see:</p>
  
  <p>1 - how to use the public key to verify the signature using 1024 bits (without the token - we need to verify on a machine without the token).</p>
  
  <p>or </p>
  
  <p>2 - how to set whatever is incorrect so that we can get passed the exception -- which I think is the better idea.  </p>
  
  <p>Does anyone have any advice on what I can do about this exception or what might be causing it?</p>
  
  <p>Full exception details below:</p>
  
  <p>HResult = -2147024809
  Message = The parameter is incorrect.
  Stack Trace </p>
  
  <p>at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
     at System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash, Int32 cbHash, ObjectHandleOnStack retSignature)
     at System.Security.Cryptography.Utils.SignValue(SafeKeyHandle hKey, Int32 keyNumber, Int32 calgKey, Int32 calgHash, Byte[] hash)
     at System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] rgbHash, Int32 calgHash)
     at System.Security.Cryptography.RSACryptoServiceProvider.SignHash(Byte[] rgbHash, String str)
     at TE.Program.Main(String[] args) in z:\Work\compusolve\enctest\TE\TE\Program.cs:line 77</p>