class Wutang::Encryption

Constants

SEPARATOR

Attributes

aes[RW]
key[RW]

Public Class Methods

new(passphrase) click to toggle source
# File lib/wutang/encryption.rb, line 7
def initialize(passphrase)
  @aes         = ::OpenSSL::Cipher::Cipher.new("AES-256-CBC")
  @aes.padding = 1
  @key         = Digest::SHA256.digest(passphrase)
end

Public Instance Methods

decrypt(value) click to toggle source
# File lib/wutang/encryption.rb, line 20
def decrypt(value)
  return value if value == '' || value.nil?
  iv, value = Base64::decode64(value.to_s).split(SEPARATOR)
  aes.decrypt
  aes.key = key
  aes.iv  = iv
  aes.update(value) + aes.final
end
encrypt(value) click to toggle source
# File lib/wutang/encryption.rb, line 13
def encrypt(value)
  return value if value == '' || value.nil?
  aes.encrypt
  aes.key = key
  Base64::encode64("#{aes.random_iv}#{SEPARATOR}#{aes.update(value.to_s) + aes.final}")
end