OpenSSL::Cipher.new 加密解密

吃可爱长大的小学妹 提交于 2019-11-27 02:15:47

 

 

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