好的,我發現它。我用MappedKeyPairProvider類:
sshd.setKeyPairProvider(new MappedKeyPairProvider(loadKeyPair("certificateFile.p12")));
隨着loadKeyPair定義如下:
public static loadKeyPair(String path) throws KeyStoreException, CertificateException, NoSuchAlgorithmException, IOException, UnrecoverableKeyException, NoSuchProviderException {
KeyStore p12 = KeyStore.getInstance("pkcs12");
p12.load(new FileInputStream(path), "certPassword".toCharArray());
java.security.cert.Certificate cert = p12.getCertificate("myAlias");
PublicKey publicKey = cert.getPublicKey();
PrivateKey key = (PrivateKey)p12.getKey("myAlias", "certPassword".toCharArray());
return new KeyPair(publicKey, key);
}
請注意,我的證書存儲在PKCS12格式。
如果運行bin \ sshd.bat,您是否找到如此配置身份驗證的方法? –
不,對不起。我以編程方式完成了這一切。 –
謝謝!對於任何偶然發現的人:集成身份驗證被固定爲「Objects.equals(用戶名,密碼)」,因此您可以登錄例如作爲「根」,「根」。 –