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")
new SecretOptions()
.setType("HS256")
.setSecret("password")
以下示例演示了如何在 Eclipse Vert.x 4 中使用 PubSecKeyOptions
类的方法。
new PubSecKeyOptions() .setAlgorithm("HS256") .setSecretKey("password")
new PubSecKeyOptions()
.setAlgorithm("HS256")
.setSecretKey("password")
6.3.2. 公钥管理中的更新 复制链接链接已复制到粘贴板!
在 Eclipse Vert.x 3.x 中,公钥密钥管理中的配置对象假定为:
- 密钥配置为密钥对。
- 密钥数据是 PKCS8 编码的字符串,没有标准分隔符。
以下示例演示了如何在 Eclipse Vert.x 3.x 中配置密钥对。
在 Eclipse Vert.x 4 中,您必须指定公钥和私钥。
以下示例演示了如何在 Eclipse Vert.x 4 中配置密钥对。
现在,您可以使用 PubSecKeyOptions
处理 X509 证书。
PubSecKeyOptions x509Certificate = new PubSecKeyOptions() // the buffer is the exact contents of the PEM file and had boundaries included in it .setBuffer(x509PemString);
PubSecKeyOptions x509Certificate =
new PubSecKeyOptions()
// the buffer is the exact contents of the PEM file and had boundaries included in it
.setBuffer(x509PemString);
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");
new KeyStoreOptions()
.setPath("path/to/keystore.jks")
.setPassword("keystore-password");
在 Eclipse Vert.x 4 中,假定默认格式是 JDK 配置的默认格式。格式是 Java 9 及更高版本中的 PKCS12
。
以下示例演示了如何在 Eclipse Vert.x 4 中载入 jceks
密钥存储。