class Slosilo::Migration::Symmetric

Public Class Methods

new() click to toggle source
# File lib/slosilo/migration/symmetric.rb, line 3
def initialize
  @cipher = OpenSSL::Cipher.new 'AES-256-CBC'
end

Public Instance Methods

cipher_name() click to toggle source

This lets us do a final sanity check in migrations from older encryption versions

# File lib/slosilo/migration/symmetric.rb, line 8
def cipher_name
  @cipher.name
end
decrypt(ciphertext, opts = {}) click to toggle source
# File lib/slosilo/migration/symmetric.rb, line 21
def decrypt ciphertext, opts = {}
  @cipher.reset
  @cipher.decrypt
  @cipher.key = opts[:key]
  @cipher.iv, ctxt = ciphertext.unpack("a#{@cipher.iv_len}a*")
  ptxt = @cipher.update(ctxt)
  ptxt + @cipher.final
end
encrypt(plaintext, opts = {}) click to toggle source
# File lib/slosilo/migration/symmetric.rb, line 12
def encrypt plaintext, opts = {}
  @cipher.reset
  @cipher.encrypt
  @cipher.key = opts[:key]
  @cipher.iv = iv = random_iv
  ctxt = @cipher.update(plaintext)
  iv + ctxt + @cipher.final
end
random_iv() click to toggle source
# File lib/slosilo/migration/symmetric.rb, line 30
def random_iv
  @cipher.random_iv
end
random_key() click to toggle source
# File lib/slosilo/migration/symmetric.rb, line 34
def random_key
  @cipher.random_key
end