使用具有 Java 安全性的authorized_keys 中的公钥
如何使用系统 authorized_keys
文件中的条目来实现 java.security.PublicKey
?我特别想将authorized_keys 文件中的公钥与Apache SSHD PublickeyAuthenticator
接口中可用的公钥进行比较。
How can I use an entry from the systems authorized_keys
file for a java.security.PublicKey
implementation? I specifically want to compare a public key from the authorized_keys file with a public key available in the Apache SSHD PublickeyAuthenticator
interface.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我很惊讶没有任何明显的证据表明这一点。我很好奇并实现了一种解码authorized_keys 文件的方法。这取决于用于 Base64 解码的 Apache Commons Codec。
I was surprised there's nothing apparent out there for this. I got curious and implemented a way to decode
authorized_keys
files. This depends on Apache Commons Codec for Base64 decoding.如果您想反转该过程,即将
PublicKey
Java 对象编码为 Linuxauthorized_keys
条目格式,可以使用以下代码:If you want reverse the process, i.e. encode a
PublicKey
Java object to a Linuxauthorized_keys
entry format, one can use this code:相同的解决方案,但将decodeInt()委托给DataInputStream。
一旦 KeyFactory 已经知道 RSA 算法,我就从原始代码中删除它。
原始来源:https: //github.com/ragnar-johannsson/CloudStack/blob/master/utils/src/com/cloud/utils/crypt/RSAHelper.java
The same solution but delegates the decodeInt() to the DataInputStream.
I remove from the original code the BouncyCastleProvider for the KeyFactory as soon as it already knows the RSA algorithm.
Original source : https://github.com/ragnar-johannsson/CloudStack/blob/master/utils/src/com/cloud/utils/crypt/RSAHelper.java
致 WhiteFang34,
您的代码非常棒,对我也很有用,但它有一个小错误。
Base64.decodeBase64 方法仅接收字节数组。所以我就这样固定了。
无论如何,感谢您编写代码。我希望您能将此代码上传到 github 或其他地方,或者允许我上传到我的 github 存储库。
To WhiteFang34,
Your code is awesome and useful for me too, but it has a tiny bug.
Base64.decodeBase64 method receives only byte array. So I fixed like this.
Anyway, thanks for writing code. I hope you to upload this code to github or elsewhere, or to allow me uploading into my github repos.