https://cloud.tencent.com/developer/section/1379183 OpenSSL::Cipher.new application_controller.rb def decrypter(data) key = ENV['ENCRYPTION_KEY'] iv = ENV['ENCRYPTION_IV'] decipher = OpenSSL::Cipher.new('des3') decipher.decrypt decipher.key = key decipher.iv = iv decipher.update(Base64.decode64(data)) + decipher.final end module aaaService def self.encrypt(plain_text) cipher = OpenSSL::Cipher.new('AES-128-CBC') cipher.encrypt cipher.key = Base64.decode64(ENV['MIDDLxxxx_ENCRYPTION_KEY']) cipher.iv = iv = cipher.random_iv encrypted = cipher.update(plain_text) + cipher.final final_string = iv + encrypted CGI.escape(Base64.encode64(final_string)) end end 来源:https://www.cnblogs.com/iwangzheng/p/11337782.html 标签 OpenSSL iv