6.3. 密钥管理的变化


在 Eclipse Vert.x 4 中,处理密钥有重大更新。最重要的更改是,当密钥加载时,公共缓冲区和私有缓冲之间没有区别。

以下的类已更新:

  • io.vertx.ext.auth.KeyStoreOptions,用于 jce 密钥存储
  • io.vertx.ext.auth.SecretOptions,用于处理对称 secret
  • io.vertx.ext.auth.PubSecKeyOptions,用于处理公共 secret 密钥

下一节描述了关键管理中的更改。

6.3.1. Secret 选项类不再可用

SecretOptions 类不再可用。使用新的 PubSecKeyOptions 类来用于加密密钥。

以下示例演示了如何在 Eclipse Vert.x 3.x 版本中使用 SecretOptions 类方法。

new SecretOptions()
    .setType("HS256")
    .setSecret("password")
Copy to Clipboard Toggle word wrap

以下示例演示了如何在 Eclipse Vert.x 4 中使用 PubSecKeyOptions 类的方法。

new PubSecKeyOptions()
    .setAlgorithm("HS256")
    .setSecretKey("password")
Copy to Clipboard Toggle word wrap

6.3.2. 公钥管理中的更新

在 Eclipse Vert.x 3.x 中,公钥密钥管理中的配置对象假定为:

  • 密钥配置为密钥对。
  • 密钥数据是 PKCS8 编码的字符串,没有标准分隔符。

以下示例演示了如何在 Eclipse Vert.x 3.x 中配置密钥对。

new PubSecKeyOptions()
  .setPublicKey(
    // remove the PEM boundaries
    pubPemString
      .replaceAll("-----BEGIN PUBLIC KEY----")
      .replaceAll("-----END PUBLIC KEY----"))
  .setSecretKey(
    // remove the PEM boundaries
    secPemString
      .replaceAll("-----BEGIN PUBLIC KEY----")
      .replaceAll("-----END PUBLIC KEY----"));
Copy to Clipboard Toggle word wrap

在 Eclipse Vert.x 4 中,您必须指定公钥和私钥。

以下示例演示了如何在 Eclipse Vert.x 4 中配置密钥对。

PubSecKeyOptions pubKey =
  new PubSecKeyOptions()
    // the buffer is the exact contents of the PEM file and had boundaries included in it
    .setBuffer(pubPemString);

PubSecKeyOptions secKey =
  new PubSecKeyOptions()
    // the buffer is the exact contents of the PEM file and had boundaries included in it
    .setBuffer(secPemString);
Copy to Clipboard Toggle word wrap

现在,您可以使用 PubSecKeyOptions 处理 X509 证书。

PubSecKeyOptions x509Certificate =
  new PubSecKeyOptions()
    // the buffer is the exact contents of the PEM file and had boundaries included in it
    .setBuffer(x509PemString);
Copy to Clipboard Toggle word wrap

6.3.3. 密钥存储管理的变化

在 Eclipse Vert.x 3.x 中,KeyStoreOptions 假定密钥存储格式为 jceks,而存储的密码与密钥的密码相同。由于 jceks 是专有格式,建议使用标准的格式,如 JDK。

当在 Eclipse Vert.x 4 中使用 KeyStoreOptions 时,可以指定存储类型。例如,可以设置 PKCS11、P PKCS12 等存储类型。默认存储类型是 jceks

在 Eclipse Vert.x 3.x 中,所有密钥存储条目都共享相同的密码,即密钥存储密码。在 Eclipse Vert.x 4 中,每个密钥存储条目都可以有专用密码。如果您不想为每个密钥存储条目设置密码,您可以将密钥存储密码配置为所有条目的默认密码。

以下示例演示了如何在 Eclipse Vert.x 3.x 中加载 jceks 密钥存储。

new KeyStoreOptions()
  .setPath("path/to/keystore.jks")
  .setPassword("keystore-password");
Copy to Clipboard Toggle word wrap

在 Eclipse Vert.x 4 中,假定默认格式是 JDK 配置的默认格式。格式是 Java 9 及更高版本中的 PKCS12

以下示例演示了如何在 Eclipse Vert.x 4 中载入 jceks 密钥存储。

new KeyStoreOptions()
  .setPath("path/to/keystore.jks")
  // Modern JDKs use `jceks` keystore. But this type is not the default
  // If the type is not set to `jceks` then probably `pkcs12` will be used
  .setType("jceks")
  .setPassword("keystore-password")
  // optionally if your keys have different passwords
  // and if a key specific id is not provided it defaults to
  // the keystore password
  .putPasswordProtection("key-id", "key-specific-password");
Copy to Clipboard Toggle word wrap
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat