Create private key dose not work by c# #4120
Replies: 2 comments
-
Hi, @bonnlee2024, how's you going? It's nice to know you are working on ShellHub. However, we would to know why are you generating the keys using C#? You could use |
Beta Was this translation helpful? Give feedback.
0 replies
-
Closing this discussion due to no response. Feel free to reopen or start a new one if needed. Thanks! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Result like this:
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAB3NzaC1y
c2GrB/Yi21x3sA+EaCMZ563a47ydR82RmK/XsaqTYDZUjbgOkuMeXT0gHd0wbHym
70Kyw2tnP7Z85e6uGWXDuvZB/hbuB2U55Y4XjGm2ElSkkGoBXZGZZAgr0YAsBUXr
EkBkaRWR8sep19nYom9JDlt7jge2sGiGX8ZFmzYg8SIqciEcThr3KBeJn8FfeP38
yQS+8whdkCAihxCU9b84em5/iu+5ffxE5kJo/AP1ekqB7bROzaNEnHcuw5nA8nJc
TUMHLNKgIja2P1o+V5P8t8sz7rW4YwyM7ZRaPev81qOw0OdFWvbuiJvS4kUU25qW
h3qmj2M9fhLipoOztxs5n+arAQABywQAAMyjCwnMowsJAAAAB3NzaC1yc2EBAQAA
AKsH9iLbXHewD4RoIxnnrdrjvJ1HzZGYr9exqpNgNlSNuA6S4x5dPSAd3TBsfKbv
QrLDa2c/tnzl7q4ZZcO69kH+Fu4HZTnljheMabYSVKSQagFdkZlkCCvRgCwFResS
QGRpFZHyx6nX2diib0kOW3uOB7awaIZfxkWbNiDxIipyIRxOGvcoF4mfwV94/fzJ
BL7zCF2QICKHEJT1vzh6bn+K77l9/ETmQmj8A/V6SoHttE7No0Scdy7DmcDyclxN
Qwcs0qAiNrY/Wj5Xk/y3yzPutbhjDIztlFo96/zWo7DQ50Va9u6Im9LiRRTbmpaH
eqaPYz1+EuKmg7O3Gzmf5qsEAAAAAAEAAQEBAAAAHucR3Kt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JMGBAAAAAMis6I6DSQwYOEKm7EDE3ybmXCGVIFOuokIB8JLQFzdy9XZ+QlnXAqjw
0NKGw1QDC6MUGTPON9I8eZc3RLeNFE92YJLj15JhM37HbvcteoQ49SNWTYcVxgNf
brTHEIRNNXdcNErzOlmQNnT6wYoPrrrWBJGWv/yzzm+kwkbswa1vbm8gY29tbWVu
dAAAAA==
-----END OPENSSH PRIVATE KEY-----
Core code like this:
private static string WriteOpenSshPrivateKey(RsaPrivateCrtKeyParameters privateKey, TextWriter writer1)
{
using (var ms = new MemoryStream())
{
using (var writer = new BinaryWriter(ms))
{
writer.Write(_encoding.GetBytes("openssh-key-v1\0"));
writer.Write(_encoding.GetBytes("none"));
writer.Write(_encoding.GetBytes("none"));
writer.Write(new byte[] { 1 });
private static byte[] GetRsaPublicKeyBlob(RsaPrivateCrtKeyParameters privateKeyParams)
{
using (MemoryStream ms = new MemoryStream())
{
using (BinaryWriter writer = new BinaryWriter(ms))
{
writer.Write(Encoding.UTF8.GetBytes("ssh-rsa"));
writer.Write(GetBytes(privateKeyParams.Modulus));
writer.Write(GetBytes(privateKeyParams.PublicExponent));
private static void WriteMpInt(BinaryWriter writer, Org.BouncyCastle.Math.BigInteger value)
{
var bytes = value.ToByteArrayUnsigned();
writer.Write(BitConverter.GetBytes(bytes.Length + 1)); // length
writer.Write((byte)(bytes[0] < 0 ? 0 : 0)); // leading zero for positive number
writer.Write(bytes); // value
}
Beta Was this translation helpful? Give feedback.
All reactions