【问题标题】:Public key validation using jsch library or java使用 jsch 库或 java 的公钥验证
【发布时间】:2018-02-26 15:25:07
【问题描述】:

当我使用 java 库方法生成公钥时,它显示为

Sun RSA public key, 1024 bits
  modulus: 90455558766847231187855444386104902055754158435274375899360135171624950510999..
  public exponent: 65537

当我使用任何在线门户生成时,例如http://travistidwell.com/blog/2013/09/06/an-online-rsa-public-and-private-key-generator/ 它显示像

-----BEGIN PUBLIC KEY-----
MIGeMA0GCSqGSIb3DQEBAQUAA4GMADCBiAKBgE3xIde7MizPdmyJ3GgDmPcLsfAY
.............
-----END PUBLIC KEY-----

其实问题是: 如果我使用默认的 java 库验证公钥

PublicKey key = KeyFactory.getInstance("RSA")
                    .generatePublic(new X509EncodedKeySpec(pub));

我收到无效密钥错误。

如果有人知道,如何使用 JSCH 库验证这些密钥或使用 java 默认库验证门户生成的公钥。

【问题讨论】:

  • “验证这些密钥” 是什么意思?你的用例是什么? - 它是什么意思“它显示像” - 你如何“显示” 它?

标签: java validation key public jsch


【解决方案1】:

我不确定我是否理解你的问题。

但也许,你正在寻找KeyPair.writeSECSHPublicKey

/**
 * Writes the public key with the specified comment to the output stream in
 * the format defined in https://www.ietf.org/rfc/rfc4716.txt
 * @param out output stream 
 * @param comment comment
 */
public void writeSECSHPublicKey(java.io.OutputStream out, String comment)

/**
 * Writes the public key with the specified comment to the output stream in
 * the format defined in https://www.ietf.org/rfc/rfc4716.txt
 * @param name file name
 * @param comment comment
 * @see #writeSECSHPublicKey(java.io.OutputStream out, String comment)
 */
public void writeSECSHPublicKey(String name, String comment)

【讨论】:

    猜你喜欢
    • 2021-12-18
    • 1970-01-01
    • 2016-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-01
    • 2013-12-26
    相关资源
    最近更新 更多