0

我有一个使用 Elytron 的工具创建的凭证存储,它提供了一个明文密码:“mypassword”。在我的 Java 程序中,我可以使用以下代码连接到商店;

Password storePassword = ClearPassword.createRaw(ClearPassword.ALGORITHM_CLEAR,"mypassword");
CredentialStore.ProtectionParameter protectionParameter = new CredentialStore.CredentialSourceProtectionParameter(
                    IdentityCredentials.NONE.withCredential(new PasswordCredential(storePassword)));
Provider provider = new WildFlyElytronPasswordProvider();
Security.addProvider(provider);
CredentialStore credentialStore = CredentialStore.getInstance(KeyStoreCredentialStore.KEY_STORE_CREDENTIAL_STORE);
// Configure and Initialise the CredentialStore
String configPath = System.getProperty("jboss.server.data.dir");
Map<String, String> configuration = new HashMap<>();
String path = configPath + File.separator + "credentials" + File.separator + "csstore.jceks";
configuration.put("keyStoreType", "JCEKS");
configuration.put("location", path);
configuration.put("modifiable", "false");
//Initialize credentialStore
credentialStore.initialize(configuration, protectionParameter);

但是,我现在想使用加密密码而不是明文连接到凭证存储。为此,我再次使用 Elytron 的工具使用以下命令创建了“mypassword”的蒙面密码;

elytron-tool.sh mask --salt 12345678 --iteration 123 --secret mypassword;

这里盐和迭代的值是随机的,可以是任何值。上面的命令给了我掩码密码;

MASK-38PaKyS.9hHaRq7pAaE5tB;12345678;123

我现在需要一种在我的 Java 程序中使用此屏蔽密码连接到凭证存储的方法。我发现还有一个名为“MaskedPassword”的类,我可能会使用它,但我不知道如何使用。

有什么建议么?

4

1 回答 1

0

我们可以使用以下代码创建它...

Password storePassword = MaskedPassword.createRaw(MaskedPassword.ALGORITHM_MASKED_MD5_DES, <CREDENTIAL_STORE_ENTRY_PREFIX>.toCharArray(), 120,"12345678".getBytes(StandardCharsets.UTF_8),"MASK-38PaKyS.9hHaRq7pAaE5tB".getBytes(StandardCharsets.UTF_8)); …………

于 2022-02-21T05:02:11.817 回答