1 - Please use> = 2048 bits in your key to protect up to ~ 2025.
The above is from 2012, but I came across this while trying to create the ssh-rsa key for Putty / Linux server connections.
I just solved a similar problem of creating the ssh-rsa public key in the appropriate format to fit PuttyGen.
For Microsoft.net RSACryptoServiceProvider it will look like
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(3072); byte[] sshrsa_bytes = Encoding.Default.GetBytes("ssh-rsa"); byte[] n = RSA.ExportParameters(false).Modulus; byte[] e = RSA.ExportParameters(false).Exponent; string buffer64; using (MemoryStream ms = new MemoryStream()) { ms.Write(ToBytes(sshrsa_bytes.Length), 0, 4); ms.Write(sshrsa_bytes, 0, sshrsa_bytes.Length); ms.Write(ToBytes(e.Length), 0, 4); ms.Write(e, 0, e.Length); ms.Write(ToBytes(n.Length+1), 0, 4);
You can see my secret key, which I used for testing, and the link to the source code putty gen https://www.cameronmoten.com/2017/12/21/rsacryptoserviceprovider-create-a-ssh-rsa-public-key/
I work at Microsoft, but this is not a personal answer from Microsoft.
Original mail for BouncyCastle ( Link )
source share