Class: Sentry::SymmetricSentry

Inherits:
Object
  • Object
show all
Defined in:
lib/sentry/symmetric_sentry.rb

Constant Summary collapse

@@default_algorithm =
'DES-EDE3-CBC'
@@default_key =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SymmetricSentry

Returns a new instance of SymmetricSentry.



6
7
8
# File 'lib/sentry/symmetric_sentry.rb', line 6

def initialize(options = {})
  @algorithm = options[:algorithm] || @@default_algorithm
end

Instance Attribute Details

#algorithmObject

Returns the value of attribute algorithm.



5
6
7
# File 'lib/sentry/symmetric_sentry.rb', line 5

def algorithm
  @algorithm
end

Class Method Details

.decrypt(data, key = nil) ⇒ Object



59
60
61
# File 'lib/sentry/symmetric_sentry.rb', line 59

def decrypt(data, key = nil)
  self.new.decrypt(data, key)
end

.decrypt_from_base64(text, key = nil) ⇒ Object



63
64
65
# File 'lib/sentry/symmetric_sentry.rb', line 63

def decrypt_from_base64(text, key = nil)
  self.new.decrypt_from_base64(text, key)
end

.default_algorithmObject



35
36
37
# File 'lib/sentry/symmetric_sentry.rb', line 35

def default_algorithm
  @@default_algorithm
end

.default_algorithm=(value) ⇒ Object



39
40
41
# File 'lib/sentry/symmetric_sentry.rb', line 39

def default_algorithm=(value)
  @@default_algorithm = value
end

.default_keyObject



43
44
45
# File 'lib/sentry/symmetric_sentry.rb', line 43

def default_key
  @@default_key
end

.default_key=(value) ⇒ Object



47
48
49
# File 'lib/sentry/symmetric_sentry.rb', line 47

def default_key=(value)
  @@default_key = value
end

.encrypt(data, key = nil) ⇒ Object



51
52
53
# File 'lib/sentry/symmetric_sentry.rb', line 51

def encrypt(data, key = nil)
  self.new.encrypt(data, key)
end

.encrypt_to_base64(text, key = nil) ⇒ Object



55
56
57
# File 'lib/sentry/symmetric_sentry.rb', line 55

def encrypt_to_base64(text, key = nil)
  self.new.encrypt_to_base64(text, key)
end

Instance Method Details

#decrypt(data, key = nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/sentry/symmetric_sentry.rb', line 22

def decrypt(data, key = nil)
  key = check_for_key!(key)
  des = encryptor
  des.decrypt(key)
  text = des.update(data)
  text << des.final
end

#decrypt_from_base64(text, key = nil) ⇒ Object



30
31
32
# File 'lib/sentry/symmetric_sentry.rb', line 30

def decrypt_from_base64(text, key = nil)
  decrypt(Base64.decode64(text), key)
end

#encrypt(data, key = nil) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/sentry/symmetric_sentry.rb', line 10

def encrypt(data, key = nil)
  key = check_for_key!(key)
  des = encryptor
  des.encrypt(key)
  data = des.update(data)
  data << des.final
end

#encrypt_to_base64(text, key = nil) ⇒ Object



18
19
20
# File 'lib/sentry/symmetric_sentry.rb', line 18

def encrypt_to_base64(text, key = nil)
  Base64.encode64(encrypt(text, key))
end