Sha256: 7537bea4f97bfa74ec0f5d28782c4104bf336339f6ead1bf2dbe3a52f558dc38

Contents?: true

Size: 636 Bytes

Versions: 1

Compression:

Stored size: 636 Bytes

Contents

require "openssl"
require "base64"

module Parsel
  autoload :Version, "parsel/version"

  def self.encrypt(key, data)
    encode cipher(:encrypt, key, data)
  end

  def self.decrypt(key, data)
    cipher(:decrypt, key, decode(data))
  rescue Exception
    false
  end

  private
  def self.cipher(mode, key, data)
    cipher = OpenSSL::Cipher.new("AES-256-CBC").public_send(mode)
    cipher.key = Digest::SHA256.digest(key)
    cipher.iv = "f89209ffcdd1a225"
    cipher.update(data) + cipher.final
  end

  def self.encode(data)
    Base64.encode64(data).chomp
  end

  def self.decode(data)
    Base64.decode64(data).chomp
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
parsel-0.1.0 lib/parsel.rb