本文整理汇总了Java中org.wildfly.security.password.spec.EncryptablePasswordSpec类的典型用法代码示例。如果您正苦于以下问题:Java EncryptablePasswordSpec类的具体用法?Java EncryptablePasswordSpec怎么用?Java EncryptablePasswordSpec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
EncryptablePasswordSpec类属于org.wildfly.security.password.spec包,在下文中一共展示了EncryptablePasswordSpec类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createConfiguration
import org.wildfly.security.password.spec.EncryptablePasswordSpec; //导入依赖的package包/类
@Override
public Map<String, String> createConfiguration(final Map<String, String> attributes)
throws GeneralSecurityException, IOException {
final Provider provider = ProviderHelper
.provider(option(attributes, "provider", ProviderHelper.WILDFLY_PROVIDER));
final String algorithm = option(attributes, "algorithm", DEFAULT_ALGORITHM);
final PasswordFactory passwordFactory = PasswordFactory.getInstance(algorithm, provider);
final String password = option(attributes, "password", null);
final String salt = option(attributes, "salt", "");
final String iterations = option(attributes, "iterations", "");
final AlgorithmParameterSpec algorithmParameterSpec;
if (salt.isEmpty() && iterations.isEmpty()) {
algorithmParameterSpec = null;
} else if (salt.isEmpty()) {
algorithmParameterSpec = new IteratedPasswordAlgorithmSpec(parseInt(iterations));
} else {
final byte[] saltBytes = Base64.getDecoder().decode(salt);
algorithmParameterSpec = new IteratedSaltedPasswordAlgorithmSpec(parseInt(iterations), saltBytes);
}
final EncryptablePasswordSpec keySpec = new EncryptablePasswordSpec(password.toCharArray(),
algorithmParameterSpec);
final MaskedPassword maskedPassword = passwordFactory.generatePassword(keySpec).castAs(MaskedPassword.class);
final MaskedPasswordAlgorithmSpec maskedPasswordAlgorithmSpec = maskedPassword.getParameterSpec();
final Map<String, String> configuration = new HashMap<>();
final Encoder encoder = Base64.getEncoder();
if (!DEFAULT_ALGORITHM.equals(algorithm)) {
configuration.put(CREDENTIAL_STORE_PROTECTION_ALGORITHM, algorithm);
}
configuration.put(CREDENTIAL_STORE_PROTECTION, encoder.encodeToString(maskedPassword.getMaskedPasswordBytes()));
final AlgorithmParameters algorithmParameters = AlgorithmParameters.getInstance(algorithm, provider);
algorithmParameters.init(maskedPasswordAlgorithmSpec);
final byte[] encoded = algorithmParameters.getEncoded();
configuration.put(CREDENTIAL_STORE_PROTECTION_PARAMS, encoder.encodeToString(encoded));
return configuration;
}