Skip to content

Instantly share code, notes, and snippets.

@ryochin
Created July 22, 2022 09:28
Show Gist options
  • Save ryochin/05754f76c596bc7dac4f99110b2fef95 to your computer and use it in GitHub Desktop.
Save ryochin/05754f76c596bc7dac4f99110b2fef95 to your computer and use it in GitHub Desktop.
Rails: AES decryption using MySQL
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