我试图将其用于我的密码加密/解密。 但每次它为同一密码提供不同的加密值。那我该如何使用以下代码和jasypt配置?
def authenticate(){
def jasyptConfig = grailsApplication.config.jasypt
org.jasypt.encryption.pbe.StandardPBEStringEncryptor stringEncryptor =
new org.jasypt.encryption.pbe.StandardPBEStringEncryptor(jasyptConfig)
def encrypted = stringEncryptor.encrypt(params.password)
}
jasypt {
algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC"
providerName = "BC"
password = "test"
keyObtentionIterations = 1000
}
答案 0 :(得分:1)
盐!
如果您不在乎,只需将ZeroSaltGenerator实例设置为您的加密器即可。默认情况下,它是RandomSaltGenerator,因此输出不同。
答案 1 :(得分:0)
如果您想使用ZeroSaltGenerator,则必须进行以下更改: 在你的config.groovy里面:
jasypt {
encryptorRegisteredName = "gormEncryptor"
}
在您的resources.groovy:
beans = {
hibernateStringEncryptor(HibernatePBEStringEncryptor) {
registeredName = "gormEncryptor"
algorithm = "PBEWITHSHA256AND256BITAES-CBC-BC"
providerName = "BC"
password = "test"
keyObtentionIterations = 1
saltGenerator = new org.jasypt.salt.ZeroSaltGenerator()
}
}
每次都会生成相同的加密值。