From 0ee7c6330cc7d9333047b03cc82069d71b33cbad Mon Sep 17 00:00:00 2001 From: David Kocher Date: Thu, 12 Oct 2023 11:34:53 +0200 Subject: [PATCH] Fix #902. --- .../sshj/transport/verification/OpenSSHKnownHosts.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java b/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java index 02ef7de41..7d71e1aa1 100644 --- a/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java +++ b/src/main/java/net/schmizz/sshj/transport/verification/OpenSSHKnownHosts.java @@ -41,6 +41,7 @@ import java.security.PublicKey; import java.security.spec.RSAPublicKeySpec; import java.util.ArrayList; +import java.util.Arrays; import java.util.Base64; import java.util.List; @@ -468,7 +469,8 @@ public String getLine() { } private String getKeyString(PublicKey pk) { - return Base64.getEncoder().encodeToString(pk.getEncoded()); + final Buffer.PlainBuffer buf = new Buffer.PlainBuffer().putPublicKey(pk); + return Base64.getEncoder().encodeToString(Arrays.copyOfRange(buf.array(), buf.rpos(), buf.available())); } protected String getHostPart() {