Sha256: b88f99a765d3806f23af49174a5e3f51c666dfd2de82203b59bae3010295a86f
Contents?: true
Size: 712 Bytes
Versions: 8
Compression:
Stored size: 712 Bytes
Contents
module Slosilo class Symmetric def initialize @cipher = OpenSSL::Cipher.new 'AES-256-CBC' end 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 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 def random_iv @cipher.random_iv end def random_key @cipher.random_key end end end
Version data entries
8 entries across 8 versions & 1 rubygems