Created
July 22, 2022 09:28
-
-
Save ryochin/05754f76c596bc7dac4f99110b2fef95 to your computer and use it in GitHub Desktop.
Rails: AES decryption using MySQL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
query = 'select AES_DECRYPT(FROM_BASE64(:encrypted), :key) as plain' | |
sql = ActiveRecord::Base.sanitize_sql_array([ | |
query, encrypted: '+mACVel1fgUZIc2Dd+CiFw==', key: 'secret' | |
]) | |
if (result = ActiveRecord::Base.connection.select_all(sql)).present? | |
result.to_a.first.dig('plain') | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment