Я пытаюсь расшифровать зашифрованный ключ с помощью пароля. Я читаю это из моего файла свойств. Расшифровка не удалась, и причина java.security.NoSuchAlgorithmException: PBEWithMD5AndDES SecretKeyFactory not available
. Пробовал с BasicTextEncryptor
, который использует PBEWithMD5AndDES
в качестве алгоритма по умолчанию. Когда я увидел упомянутое исключение, я попытался использовать StandardPBEStringEncryptor
. Я также установил алгоритм, но все еще сталкиваюсь с той же проблемой. Ниже приведен код
public class PasswordDecrypt {
private static char[] password;
static {
try (InputStream in = PasswordDecrypt.class.getClassLoader().getResourceAsStream("application-unitTest.properties");) {
Properties props = new Properties();
props.load(in);
password = props.getProperty("jasypt.encryptor.password").toCharArray();
} catch (IOException e) {
e.printStackTrace();
}
}
public static String decrypt(String text) {
// BasicTextEncryptor decryptor = new BasicTextEncryptor();
// decryptor.setPasswordCharArray(password);
// String decryptedText = decryptor.decrypt(text);
// return decryptedText;
StandardPBEStringEncryptor decryptor = new StandardPBEStringEncryptor();
decryptor.setPasswordCharArray(password);
decryptor.setAlgorithm("PBEWithMD5AndDES"); String
decryptedText = decryptor.decrypt(text);
return decryptedText;
}
}
Я не уверен, как решить эту проблему. Попробовал изменить мавенские зависимости. Следующие были опробованы.
<dependency>
<groupId>com.github.ulisesbocchio</groupId>
<artifactId>jasypt-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.melloware</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.4</version>
</dependency>
<dependency>
<groupId>org.jasypt</groupId>
<artifactId>jasypt</artifactId>
<version>1.9.2</version>
</dependency>