diff --git a/SKSshAgent/Ssh/SshKey.cs b/SKSshAgent/Ssh/SshKey.cs index 4737522..09d4124 100644 --- a/SKSshAgent/Ssh/SshKey.cs +++ b/SKSshAgent/Ssh/SshKey.cs @@ -111,8 +111,9 @@ public static (SshKey Key, string Comment) ParseOpenSshPrivateKey(ReadOnlySpan 0; ++i) + if (privateReader.ReadByte() != i) + throw new InvalidDataException("Invalid padding."); if (!publicKey.Equals(privateKey, publicOnly: true)) throw new InvalidDataException("Mismatched public and private keys."); @@ -227,6 +228,12 @@ public char[] FormatOpenSshPrivateKey(string comment) privateWriter.WriteString(comment); privateWriter.Flush(); + for (byte i = 1; innerBuffer.WrittenCount % 8 != 0; ++i) + { + innerBuffer.GetSpan(1)[0] = i; + innerBuffer.Advance(1); + } + writer.WriteByteString(innerBuffer.WrittenSpan); writer.Flush();