首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用蒙面密码连接到Wildfly Elytron的凭证商店

用蒙面密码连接到Wildfly Elytron的凭证商店
EN

Stack Overflow用户
提问于 2022-01-31 07:25:24
回答 2查看 745关注 0票数 2

我有一个凭据商店,我创建的工具提供了一个明确的文本密码:"mypassword“。在我的Java程序中,我可以用下面的代码连接到商店;

代码语言:javascript
复制
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“的Passowrd,命令如下;

代码语言:javascript
复制
elytron-tool.sh mask --salt 12345678 --iteration 123 --secret mypassword;

在这里,salt和迭代的值都是随机的,可能是任意的。上面的命令给了我蒙面密码,即;

掩模-38PaKyS.9hHaRq7pAaE5tB;12345678;123

现在,我需要一种方法来连接到凭据存储,在我的Java程序中使用这个蒙面密码。我发现还有一个名为"MaskedPassword“的类,我可能会使用它,但我无法找到如何使用它。

有什么建议吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2022-05-02 17:07:10

当您使用elytron工具生成掩码时,您将得到带有前缀掩码的字符串,在您的情况下得到带有salt和迭代的字符串-38PaKyS.9hHaRq7pAaE5tB;12345678;123

您可以使用下面的代码来解密蒙面密码,

代码语言:javascript
复制
private char[] getUnmaskedPass(String maskedPassword) throws GeneralSecurityException {
        int maskLength = enter code here"MASK-".length();
        if (maskedPassword == null || maskedPassword.length() <= maskLength) {
            throw new GeneralSecurityException();
        }
        String[] parsed = maskedPassword.substring(maskLength).split(";");
        if (parsed.length != 3) {
            throw new GeneralSecurityException();
        }
        String encoded = parsed[0];
        String salt = parsed[1];
        int iteration = Integer.parseInt(parsed[2]);
        PasswordBasedEncryptionUtil encryptUtil = new PasswordBasedEncryptionUtil.Builder().picketBoxCompatibility().salt(salt).iteration(iteration)
                .decryptMode().build();

        return encryptUtil.decodeAndDecrypt(encoded);
    }

现在,您可以将其作为clearPassword在代码中使用。我希望这能帮上忙。

源- https://github.com/wildfly-security/wildfly-elytron-tool/blob/master/src/main/java/org/wildfly/security/tool/MaskCommand.java静态char[] decryptMasked(字符串maskedPassword)

票数 2
EN

Stack Overflow用户

发布于 2022-02-21 05:02:11

我们可以用下面的代码创建它..。

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)); ...……

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70922429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档