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

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

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

1
=
1
=
$0.18
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", "mr.x@contoso.com" },
                { "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 и сформировать вручную этот обьект на основе имеющихся приватного и публичного ключей. Надеюсь это помогло тебе!

SEND BITCOIN TIPS
User rating:

Maybe it's correct :)

User rating:

Yep....

0

Too many commands? Learning new syntax?

FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.

Boost your productivity with FavScripts.com!

Post Answer