Create RSACryptoServiceProvider object with keys defined as strings without going through X509Certificate2 object

No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.

Quite often people use X509Certificate2 object to instantiate a RSACryptoServiceProvider object:

var rsaObj = new X509Certificate2("some-cert.p12", "password", X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet).PrivateKey as RSACryptoServiceProvider;

I want to generate the RSACryptoServiceProvider object using private and public keys defined as strings, without going through X509Certificate.

Please help!

1 Answer - total earned - 0.2567 mBTC ($0.18 USD)

1 tip with total amount of 0.2567 mBTC($0.18 USD) have been sent by alex@qrid

Hi. Ты можешь использовать rsaCryptoServiceProvider.ExportParameters(true). Этот метод возвращает обьект типа RsaParameters в котором содержится информация о приватном и публичном ключах.

var payload = new Dictionary<string, object>() 
                { "sub", "" },
                { "exp", 1300819380 }

            var key = RSA.Create();

            using (RSACryptoServiceProvider rsaCryptoServiceProvider = new RSACryptoServiceProvider(2048))
                PrivateKey = rsaCryptoServiceProvider.ExportParameters(true);

                string token = Jose.JWT.Encode(payload, rsaCryptoServiceProvider, JwsAlgorithm.RS512);

                return Ok(new { Token = token });

Т.е. ты можешь подсмотреть формат RsaParameters и сформировать вручную этот обьект на основе имеющихся приватного и публичного ключей. Надеюсь это помогло тебе!


Maybe it's correct :)



Post Answer

Will Bitcoin Tipping become a new Internet Culture?

Please share our story! THANK YOU!