class Veil::Cipher::V2
Attributes
cipher[R]
iv[R]
key[R]
Public Class Methods
new(opts = {})
click to toggle source
# File lib/veil/cipher/v2.rb, line 9 def initialize(opts = {}) @cipher = OpenSSL::Cipher.new("aes-256-cbc") @key = opts[:key] ? Base64.strict_decode64(opts[:key]) : cipher.random_key @iv = opts[:iv] ? Base64.strict_decode64(opts[:iv]) : cipher.random_iv end
Public Instance Methods
decrypt(ciphertext)
click to toggle source
# File lib/veil/cipher/v2.rb, line 23 def decrypt(ciphertext) c = cipher c.decrypt c.key = key c.iv = iv JSON.parse(c.update(Base64.strict_decode64(ciphertext)) + c.final, symbolize_names: true) end
encrypt(plaintext)
click to toggle source
# File lib/veil/cipher/v2.rb, line 15 def encrypt(plaintext) c = cipher c.encrypt c.key = key c.iv = iv Base64.strict_encode64(c.update(plaintext) + c.final) end
to_hash()
click to toggle source
# File lib/veil/cipher/v2.rb, line 31 def to_hash { type: self.class.name, key: Base64.strict_encode64(key), iv: Base64.strict_encode64(iv) } end
Also aliased as: to_h