Sha256: f58ec8267b7bd765ef2e4c34cd076a6588da786741cb362ff4b9d805e164f060
Contents?: true
Size: 1.11 KB
Versions: 6
Compression:
Stored size: 1.11 KB
Contents
module Rmega module Crypto module AesCbc def aes_cbc_cipher OpenSSL::Cipher::AES.new(128, :CBC) end def aes_cbc_encrypt(key, data) cipher = aes_cbc_cipher cipher.encrypt cipher.padding = 0 cipher.key = key return cipher.update(data) + cipher.final end def aes_cbc_decrypt(key, data) cipher = aes_cbc_cipher cipher.decrypt cipher.padding = 0 cipher.key = key return cipher.update(data) + cipher.final end def aes_cbc_mac(key, data, iv) cipher = aes_cbc_cipher cipher.encrypt cipher.padding = 0 cipher.iv = iv if iv cipher.key = key # n = 0 # mac = nil # loop do # block = data[n..n+15] # break if !block or block.empty? # block << "\x0"*(16-block.size) if block.size < 16 # n += 16 # mac = cipher.update(block) # end # return mac block = data + "\x0" * ((16 - data.bytesize % 16) % 16) return cipher.update(block)[-16..-1] end end end end
Version data entries
6 entries across 6 versions & 1 rubygems