Class: ZiggeoAuth
- Inherits:
-
Object
- Object
- ZiggeoAuth
- Defined in:
- lib/classes/ZiggeoAuth.rb
Instance Method Summary collapse
- #_encrypt(plaintext) ⇒ Object
- #_generateNonce ⇒ Object
- #generate(options = {}) ⇒ Object
-
#initialize(application) ⇒ ZiggeoAuth
constructor
A new instance of ZiggeoAuth.
Constructor Details
#initialize(application) ⇒ ZiggeoAuth
Returns a new instance of ZiggeoAuth.
8 9 10 11 |
# File 'lib/classes/ZiggeoAuth.rb', line 8 def initialize(application) @application = application @cipher = nil end |
Instance Method Details
#_encrypt(plaintext) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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 ⇒ Object
37 38 39 40 |
# 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 = {}) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/classes/ZiggeoAuth.rb', line 28 def generate( = {}) data = { "application_token" => @application.token, "nonce" => self._generateNonce() } data.update() return self._encrypt(JSON.generate(data)) end |