Re: Certificates received from Windows CertStore: wrong public key (and incorrect modulus length)?
From: Michel Gallant (neutron_at_NOSPAMistar.ca)
Date: 01/20/04
- Next message: Michael Giagnocavo [MVP]: "Re: Why isn't there a Microsoft Security Application Block"
- Previous message: Hernan de Lahitte: "Re: CspParameters problem"
- In reply to: Johannes Resch: "Certificates received from Windows CertStore: wrong public key (and incorrect modulus length)?"
- Next in thread: Johannes Resch: "Re: Certificates received from Windows CertStore: wrong public key (and incorrect modulus length)?"
- Reply: Johannes Resch: "Re: Certificates received from Windows CertStore: wrong public key (and incorrect modulus length)?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Tue, 20 Jan 2004 08:06:56 -0500
Hi Johannes,
The Pinvoke to CryptoAPI should return the correct key size.
I just tried this for 1024, 2048 and 16,384 bit RSA keys and
they return the correct public key.
However, if you instantiate a .NET oRSA with only the
public key and exponent, the KeySize parameter is not properly
updated, but the oRSA can still be used for enveloping. I KeySize
parameter is available if you instantiate with a keycontainer specifier.
Note that the MSDN EncyrptTo.cs sample has a "Verbose" switch
to show the details of the key returned.
- Mitch Gallant
"Johannes Resch" <jr@xor.at> wrote in message
news:b341089e.0401200119.2dd589b3@posting.google.com...
> Hello,
>
> I'm currently writing an application in C# to support message
> integrity checks with signatures.
> For this, I need to use X.509-Certificates from files (CER encoded) as
> well as from the windows local machine certificate store.
>
> I modified the CryptoAPI P/Invoke-Examples from MSDN
>
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dncapi/html/encryptdecrypt2a.asp?f
rame=true&hidetoc=true)
> to access the windows local machine certificate store from C#.
>
> This works, I can access both public and private keys of a chosen
> certificate.
>
> For getting RSA-PK-Parameters from a C# X509Certificate, I used the
> way described in
http://groups.google.at/groups?hl=de&lr=&ie=UTF-8&oe=UTF-8&selm=OLCJILvRDHA.2768%40tk2msftngp13.phx.gbl.
> (getting the Modulus and Exponent from raw data returned from
> GetPublicKey(); see code below).
>
>
> However, if I take a closer look at the public key I get from the
> Windows Certificate store, there are two problems:
>
> 1.) the modulus length is always 128 Byte, no matter if I use PKs with
> keylengths greater than 1024 Bit.
>
> 2.) the modulus-parameter of two public keys (one extracted from
> CER-File via X509Certificate and GetPublicKey(), the other one
> received from the same certificate in Windows CertStore) don't match
> at all (they one from windows certstore is not just truncated, it
> seems to be completely different).
>
> If I open MMC and take a look at the certificates public key in the
> windows certificate-management applet, I can see the correct public
> key (correct length, same modulus as the one being extracted from
> CER-File).
>
> As I'm not a CryptoAPI-insider: could it be possible, that I forgot to
> modify some parts of the CryptoAPI-MSDN examples, that could lead to
> this behaviour?
> Any other ideas?
>
>
> Best Regards,
> Johannes Resch
>
>
> Code for getting RSA-Exponent and Modulus from raw Public-Key-Data:
>
> byte[] pk = cert.GetPublicKey();
> byte[] exp = new byte[3];
> byte[] modulus = new byte[keyLen/8];
> Array.Copy(pk, pk.Length - exp.Length, exp, 0, exp.Length);
> Array.Copy(pk, pk.Length - exp.Length - 2 - modulus.Length, modulus,
> 0, modulus.Length);
> RSAParameters rsaParams = new RSAParameters();
> rsaParams.Modulus = modulus;
> rsaParams.Exponent = exp;
- Next message: Michael Giagnocavo [MVP]: "Re: Why isn't there a Microsoft Security Application Block"
- Previous message: Hernan de Lahitte: "Re: CspParameters problem"
- In reply to: Johannes Resch: "Certificates received from Windows CertStore: wrong public key (and incorrect modulus length)?"
- Next in thread: Johannes Resch: "Re: Certificates received from Windows CertStore: wrong public key (and incorrect modulus length)?"
- Reply: Johannes Resch: "Re: Certificates received from Windows CertStore: wrong public key (and incorrect modulus length)?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|
|