主要问题就在于此.将openssh公钥解析为符合
rfc 4716
格式.唯一的问题是,它必须在java中.
使用ssh-keygen,它只是单行命令:
ssh-keygen -e -f openssh_key.pub
不幸的是,我在Java中找不到任何其他来源.甚至没有提到转换所需的任何算法或步骤.所有这些都围绕着ssh-keygen本身的使用.当然,我可以使用java.exec
来调用命令,但这是最糟糕的情况.
示例openssh密钥(已将其保留为代码格式,以便保留生成的空格/换行符):
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDwxgE7D3HYLYddNHLMFK8OfpRwwUSgxiB8fbecvkCUEktSpWikvsWTyCnl5p3uSmsGg/F1lwVPXuuVlQ4VZlYqMuEBEMRF9ADdXWWNxjO/Hd7688ow7ocncxl0xKXsH5Fc9GHvE8yfUh94F8Qm9x8M8Uux+XsNEvPG8KI/QUJWndIsHv+m//3nbEEqUTAlzsyY0mjHW/dPORhXcB5WeGH+cBRAhcp5JGKAq26TOsuNY8H+nrlxX6z03xbUN28HHdXv6uKZfpnVpl6tM0khxbh7F+tLYWeUIZ+nYaDBPINv8Mkd6Duqe/GOLtgVUIR76Adijok4w5oaKlTq27xzMurl kaushik@kaushik-HP
使用ssh-keygen解析:
---- BEGIN SSH2 PUBLIC KEY ---- Comment: "2048-bit RSA,converted by kaushik@kaushik-HP from OpenSSH" AAAAB3NzaC1yc2EAAAADAQABAAABAQDwxgE7D3HYLYddNHLMFK8OfpRwwUSgxiB8fbecvk CUEktSpWikvsWTyCnl5p3uSmsGg/F1lwVPXuuVlQ4VZlYqMuEBEMRF9ADdXWWNxjO/Hd76 88ow7ocncxl0xKXsH5Fc9GHvE8yfUh94F8Qm9x8M8Uux+XsNEvPG8KI/QUJWndIsHv+m// 3nbEEqUTAlzsyY0mjHW/dPORhXcB5WeGH+cBRAhcp5JGKAq26TOsuNY8H+nrlxX6z03xbU N28HHdXv6uKZfpnVpl6tM0khxbh7F+tLYWeUIZ+nYaDBPINv8Mkd6Duqe/GOLtgVUIR76A dijok4w5oaKlTq27xzMurl ---- END SSH2 PUBLIC KEY ----
更新:我为有类似需求的人创建了一个implementation of the conversion on gist.