How to generate ssh compatible id_rsa(.pub) from Java

前端 未结 4 545
再見小時候
再見小時候 2020-12-02 10:52

I\'m looking for a way to programmatically create ssh compatible id_rsa and id_rsa.pub files in Java.

I got as far as creating the KeyPair:

KeyPairG         


        
4条回答
  •  悲&欢浪女
    2020-12-02 11:24

    The generic solution for any PublicKey type (RSA, DSA, etc.) is a one-liner using SSHJ:

    byte[] b = new Buffer.PlainBuffer().putPublicKey(key).getCompactData()
    

    and then encode using Base64.getEncoder().encodeToString(b).

提交回复
热议问题