Keytool - 使用现有私钥生成 X.509 格式的 Public 密钥

Keytool - Generate Public key in X.509 format using existing private key

我正在尝试生成 X.509 格式的 private/public 密钥对以及我需要用于我的 SAML 应用程序的自签名证书。

这是我所做的:

  1. here 生成自签名证书和私钥并保存 它们采用 .pem 格式。
  2. 使用私钥并生成一个public密钥 使用命令 openssl rsa -in key.pem -pubout -out pubkey.pem

当我将这些密钥提供给我的 SAML 应用程序时,它在第 2 步生成的 public 密钥上出错,并显示以下消息:

java.io.IOException: Short read of DER length

我这里做错了什么?

问题

我正在尝试生成 X.509 格式的 private/public 密钥对以及我需要用于我的 SAML 应用程序的自签名证书。

回答:

(1) 在 Ubuntu 16.04 上,我 运行 以下本机 openssl 命令成功地为 Shibboleth SAML SP 应用程序生成 X.509 格式的 private/public 密钥对。

openssl genrsa -out key.pem 2048 -days 365
openssl req -new -key key.pem -out certreq.csr
openssl x509 -req -in certreq.csr -signkey key.pem -out cert.pem

(2) 我将 Shibboleth SAML SP 应用程序生成的 public cert/key(即 cert.pem)上传到 Shibboleth SAML IdP。

(3) 我通过Shibboleth SAML IdP 和OpenLDAP 提供的身份验证成功登录到Shibboleth SAML SP 应用程序。

备注:

(I) 请确保IdP 或SP 数据库为用于存储public cert/key 或私钥的Type 定义了足够的长度,例如varchar(2500)。

(II)如果你运行在Windows环境下的openssl命令,请查看我对另一个Whosebug问题的回答Git status ignore line endings / identical files / windows & linux environment / dropbox / mled从末尾删除"premature EOF"私钥和 public cert/key.

(III) How to build and run Shibboleth SAML IdP and SP using Docker container 在 GitHub 存储库中提供了有关如何构建和 运行 Shibboleth SAML IdP 和 SAML SP 测试平台的说明,以测试您的 SAML SP 应用程序。

独立的 Shibboleth SAML IdP 测试平台允许您检查日志以调试您的证书问题。