Is it possible to use the Grails Jasypt plugin outside the GORM layer for simple String encryption and decryption?

佐手、 提交于 2019-12-02 09:48:29

The plugin has jasypt dependencies and they are exported to app (plugin dependencies are transitively available to the app by default).

I think you can use the StandardPBEStringEncryptor as is based on your config.

Add the below method as an action in a sample controller (inject grailsApplication) of your app and hit it.

def standard(){
    def jasyptConfig = grailsApplication.config.jasypt
    org.jasypt.encryption.pbe.StandardPBEStringEncryptor stringEncryptor = 
           new org.jasypt.encryption.pbe.StandardPBEStringEncryptor(jasyptConfig)

    def encrypted = stringEncryptor.encrypt("Hello World")
    def decrypted = stringEncryptor.decrypt(encrypted)

    render([encrypted: encrypted, decrypted: decrypted] as JSON)
}

or just run the above method in grails console.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!