通过问题Is it possible to use the Grails Jasypt plugin outside the GORM layer for simple String encryption and decryption?的引用
我尝试将其用于我的密码加密/解密。
但是每次给同一个密码赋予不同的加密值。那么我如何使用以下代码和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
}
最佳答案
盐!
如果您不在乎,只需将ZeroSaltGenerator实例设置为您的Encryptor。默认情况下,它是RandomSaltGenerator,因此输出是不同的。
关于grails - Jailspt插件具有grails的加密/解密,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21878690/