我可以使用 jasypt 使用 EncryptableProperties 对 .properties 文件中的凭据进行加密和解密。由于我想使用自己的算法或“SHA-512”等算法,如何在 EncryptableProperties 中实现它?
有没有办法在 EncryptableProperties 上使用 ConfigurablePasswordEncryptor 或 StrongPasswordEncryptor 代替我的 StringEncryptor 或 TextEncryptor。
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("OrderMod");
Properties props = new EncryptableProperties(encryptor);
props.load(new FileInputStream("mime.properties"));
String password = props.getProperty("password");
System.out.println("password:: "+password);
最佳答案
您可以在加密器上设置算法:
StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor();
encryptor.setPassword("OrderMod");
encryptor.setAlgorithm(jasyptAlgorithm);
Properties props = new EncryptableProperties(encryptor);
其中 jasyptAlgorithm
是您要使用的更强的算法,例如 PBEWithMD5AndTripleDES
。 Jasypt 实际上并不实现任何算法,因此您需要从 JCE 提供商处找到算法列表,例如 Oracle JCA (Oracle Java 附带)或 Bouncy Castle .
如果您使用强大的算法(如 3DES),您可能需要下载并安装 Java Cryptography Extension Unlimited Strength Jurisdiction Policy Files
您提到SHA-512 ,但这根本不是加密算法。它只是一种哈希算法。许多加密进程可能能够使用 SHA-512,但其他一些算法将处理加密。
关于java - Jasypt - 如何使用 StrongPasswordEncryptor 作为 .properties 文件中的凭据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24118012/