Module: Cryptatron

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

Constant Summary collapse

VERSION =
'0.0.8'

Class Method Summary collapse

Class Method Details

.decrypt(body, magic) ⇒ Object



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

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



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

def self.encrypt(body, magic)
	setup

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