Monday, May 14, 2012

Quick way to generate RSA key with LinqPad

To generate private RSA key, we can use LinqPad Expression Executing below expression, will generate RSA key in result window.

new System.Security.Cryptography.RSACryptoServiceProvider (1024).ToXmlString (true) 

if needed, press F4 to add reference, and add reference to System.Security.dll

In Powershell
$rsa = New-Object  System.Security.Cryptography.RSACryptoServiceProvider (1024);
public key
$rsa.ToXmlString($false)
private key
$rsa.ToXmlString($true)