Casting of ECPrivateKeyParameters to RsaPrivateCrtKeyParameters

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Casting of ECPrivateKeyParameters to RsaPrivateCrtKeyParameters

RajatRokade
This post has NOT been accepted by the mailing list yet.
Hello,
I am getting an InvalidCastException when i try to cast _privateKeyEC = (RsaPrivateCrtKeyParameters ) private_key_pair.Private because private is of the type ECPrivateKeyParameters.

I tried searching in many places but could not get find a way to cast  ECPrivateKeyParameters to  RsaPrivateCrtKeyParameters.

Please help with this issue.

Below is the code snippet:

private RsaPrivateCrtKeyParameters _privateKey;



IPasswordFinder pGet = new SoftToken(PrivateKeyPassword.ToCharArray());
                var keyReader = new PemReader(new StreamReader(keyPath),pGet);
                                var key_from_pem =  keyReader.ReadObject ();
                                RsaPrivateCrtKeyParameters private_key = key_from_pem as RsaPrivateCrtKeyParameters;
                                AsymmetricCipherKeyPair private_key_pair = key_from_pem as AsymmetricCipherKeyPair;
                                if ( private_key != null){
                                        _privateKey = private_key;
                                }else if (private_key_pair != null){
                    _privateKeyEC = (RsaPrivateCrtKeyParameters )private_key_pair.Private;
                                }