class ZiggeoAuth

Public Class Methods

new(application) click to toggle source
# File lib/classes/ZiggeoAuth.rb, line 8
def initialize(application)
  @application = application
  @cipher = nil
end

Public Instance Methods

_encrypt(plaintext) click to toggle source
# File lib/classes/ZiggeoAuth.rb, line 13
def _encrypt(plaintext)
  if (@cipher == nil)
    hashed_key = Digest::MD5.hexdigest(@application.encryption_key)
    @cipher = OpenSSL::Cipher::Cipher.new("AES-256-CBC")
    @cipher.encrypt
    @cipher.padding = 1
    @cipher.key = hashed_key
  end
  iv = SecureRandom.hex(8)
  @cipher.iv = iv
  encrypted = @cipher.update(plaintext) + @cipher.final
  encrypted = encrypted.unpack("H*").first
  return iv + encrypted
end
_generateNonce() click to toggle source
# File lib/classes/ZiggeoAuth.rb, line 37
def _generateNonce()
  t = Time.new
  return t.to_i.to_s + rand(256 * 256 * 256 * 256).to_s
end
generate(options = {}) click to toggle source
# File lib/classes/ZiggeoAuth.rb, line 28
def generate(options = {})
  data = {
    "application_token" => @application.token,
    "nonce" => self._generateNonce()
  }    
  data.update(options)
  return self._encrypt(JSON.generate(data))
end