数据和文件的加密解密 – underlock

Underlock

Underlock使数据和文件的加密解密变得非常简单。它没有依赖,有一个非常小的API接口。



Installation

在应用的Gemfile中添加:

gem 'underlock'

然后执行:

$ bundle

或者这样安装:

$ gem install underlock

初始化

Underlock::Base.configure do |config|
  config.public_key  = File.read('./key.pub')
  config.private_key = File.read('./key.priv')
  config.cipher      = OpenSSL::Cipher.new('aes-256-gcm')
end

For theconfig.ciphervalue, all algorithms available inOpenSSL::Cipher.ciphersare supported.

Important Note: Choose your algorithm carefully and stick to it. It’ll kind of suck to be not able to decrypt your encrypted data.

生成公有/私有密钥对

key = OpenSSL::PKey::RSA.new 4096
puts key.to_pem
puts key.public_key.to_pem

本站文章除注明转载外,均为本站原创或编译
转载请明显位置注明出处:数据和文件的加密解密 – underlock