Module: Cryptatron

Defined in:
lib/cryptatron.rb,
lib/cryptatron/version.rb

Constant Summary collapse

VERSION =
'1.0.0'

Class Method Summary collapse

Class Method Details

.decrypt(body, magic) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cryptatron.rb', line 17

def self.decrypt(body, magic)
  setup

  begin
    body = @cipher.decrypt(body)
    raise unless body.starts_with?(magic)

    return body[magic.length..-1]
  rescue
    nil
  end
end

.encrypt(body, magic) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/cryptatron.rb', line 7

def self.encrypt(body, magic)
  setup

  begin
    Base64.strict_encode64 @cipher.encrypt(magic + body, binary: true)
  rescue
    nil
  end
end