我期待將RSA公鑰轉換爲我可以用作SSH公鑰的東西。將RSA公鑰轉換爲RFC 4716公鑰和Bouncy Castle
目前我有充氣城堡生產我看起來像這樣的公共密鑰:
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAq1Y5300i8bN+cI2U3wJE
Kh3xG/.........jbuz+WB0vvG
P25UwCle2k5siVMwbImEYsr+Xt0dsMmGVB3/6MHAqrM3QQdQ8p2E5TyzL+JYa1FT
gwIDAQAB
-----END PUBLIC KEY-----
我希望它有類似於這樣的RFC 4716格式:
ssh-rsa AAAAB3NzaC1yc2.......G1p2Ag3mZLFsks7RNHVLgMsGIAikQ==
我的代碼到目前爲止使用Bouncy Castle看起來像這樣:
var r = new Org.BouncyCastle.Crypto.Generators.RsaKeyPairGenerator();
r.Init(new KeyGenerationParameters(new SecureRandom(), 2048));
var keys = r.GenerateKeyPair();
var stringWriter = new StringWriter();
var pemWriter = new PemWriter(stringWriter);
pemWriter.WriteObject(keys.Private);
pemWriter.Writer.Flush();
stringWriter.Close();
PrivateKey = stringWriter.ToString();
stringWriter = new StringWriter();
pemWriter = new PemWriter(stringWriter);
pemWriter.WriteObject(keys.Public);
pemWriter.Writer.Flush();
stringWriter.Close();
PublicKey = stringWriter.ToString();
如何重新格式化和編碼密鑰以使其看起來像這樣?
有沒有人用Bouncy Castle或類似軟件創建過SSH公鑰?
謝謝 - 這工作完美! – Doug 2015-12-19 07:08:50
同意道格 - 非常好,並允許我生成與SFTP一起使用的密鑰。 – 2017-05-05 06:40:35