class Rtprov::Encryption
Constants
- KEY_FILE
Attributes
key[R]
Public Class Methods
decrypt(encrypted, key = load_key)
click to toggle source
# File lib/rtprov/encryption.rb, line 18 def self.decrypt(encrypted, key = load_key) new(key).decrypt(encrypted) end
encrypt(plain, key = load_key)
click to toggle source
# File lib/rtprov/encryption.rb, line 14 def self.encrypt(plain, key = load_key) new(key).encrypt(plain) end
generate_key()
click to toggle source
# File lib/rtprov/encryption.rb, line 22 def self.generate_key SecureRandom.base64(512) end
load_key()
click to toggle source
# File lib/rtprov/encryption.rb, line 10 def self.load_key ENV["ENCRYPTION_KEY"] || (File.exist?(KEY_FILE) && File.read(KEY_FILE).strip) || raise("ENCRYPTION_KEY env or encryption_key file not found") end
new(key)
click to toggle source
# File lib/rtprov/encryption.rb, line 26 def initialize(key) @key = key.dup.freeze end
Public Instance Methods
decrypt(encrypted)
click to toggle source
# File lib/rtprov/encryption.rb, line 34 def decrypt(encrypted) ReversibleCryptography::Message.decrypt(encrypted, key) end
encrypt(plain)
click to toggle source
# File lib/rtprov/encryption.rb, line 30 def encrypt(plain) ReversibleCryptography::Message.encrypt(plain, key) end