Re: RSACryptoServiceProvider.ImportParameters exception isn't helpful
From: meno abels (meno.abels_at_adviser.com)
Date: 03/17/04
- Next message: Michael Giagnocavo [MVP]: "Re: Encrypt and save in a file"
- Previous message: Sasha: "Encrypt and save in a file"
- In reply to: Jonathan Ruckert: "RE: RSACryptoServiceProvider.ImportParameters exception isn't helpful"
- Next in thread: meno abels: "Re: RSACryptoServiceProvider.ImportParameters exception isn't helpful"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: Wed, 17 Mar 2004 08:32:36 +0100
Hi Jonathan,
thanks for you quick comment but the problem is not that my private key is in an
specified format. I read it in from an internal format and generate out of these
the values for the RSAParameters struct. So I can only have the problem that
the expected byte[] are not directly interpreted as large binary numbers.
I will do a cross check by writing out the privatekey with ExportParameters and
try to use the key with openssl and import it back to my interal format.
So i can prooven that my conversion is ok. But I like to use the openssl
generate key infact of my infrastructure.
Meno
> Hi Meno,
>
> Seems like this is a bit of a problem that happens usually.
>
> Its a bit wierd but this is the way that is suggested to solve your problem. Reading the key in an XML form using the FromXMLString will not work, as it will expect two elements modulus and exponent. There must be an easier way of doing this but if you extract the modulus from the key, convert to hex and load it in byte by byte into the RSAParameters.
>
> Also it seems that the standard DER ASN1-PKCS7 encoded key and the PEM key (base 64 encoded with header and footer) is not supported. However i need to do a bit more research into this fact to be 100% sure.
>
> Hope this points you in the right direction.
>
> Regards,
> Jonathan Ruckert
>
>
> ----- meno abels wrote: -----
>
> I try to load an private key which was generated by openssl.
> To import that key i converted it to an RSAParameters structure.
> Now I think the convertion of the key is ok. So i try to
> use the key:
> RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
> rsa.ImportParameters(BuildRSAParameters());
> If I run this code i only get the very helpful exception:
> "Invalid key" from ImportParameters.
> So my problem is there is no complete documentation about
> RSAParameters only the members are named nothing about the
> format etc. So I have to use the public knowledge about
> RSA Keys which are not more than large numbers binary coded in
> byte arrays. So why should my large numbers are "Invalid key".
> What i discovered is if I use:
> RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(4096);
> RSAParameters p = rsa.ExportParameters(true);
> The structure to my p is very equal. All but the length of some
> key components are to vary by one. Which i can't explain why the
> key from openssl has such odd lengths. So i aligned the lengths
> to the lengths which are given by RSACryptoServiceProvider(4096) in
> of knowledge that the later decrypting is properly failing. But
> ImportParameters also generating the exceptions "Invalid Key"
>
> meno
>
- Next message: Michael Giagnocavo [MVP]: "Re: Encrypt and save in a file"
- Previous message: Sasha: "Encrypt and save in a file"
- In reply to: Jonathan Ruckert: "RE: RSACryptoServiceProvider.ImportParameters exception isn't helpful"
- Next in thread: meno abels: "Re: RSACryptoServiceProvider.ImportParameters exception isn't helpful"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|