Module: Rmega::Crypto::Aes

Extended by:
Aes
Included in:
Aes
Defined in:
lib/rmega/crypto/aes.rb

Instance Method Summary collapse

Instance Method Details

#cipherObject


12
13
14
# File 'lib/rmega/crypto/aes.rb', line 12

def cipher
  @cipher ||= OpenSSL::Cipher::AES.new(128, :CBC)
end

#decrypt(key, data) ⇒ Object


25
26
27
28
29
30
31
32
# File 'lib/rmega/crypto/aes.rb', line 25

def decrypt(key, data)
  cipher.reset
  cipher.padding = 0
  cipher.decrypt
  cipher.key = key.pack packing
  result = cipher.update data.pack(packing)
  result.unpack packing
end

#encrypt(key, data) ⇒ Object


16
17
18
19
20
21
22
23
# File 'lib/rmega/crypto/aes.rb', line 16

def encrypt(key, data)
  cipher.reset
  cipher.padding = 0
  cipher.encrypt
  cipher.key = key.pack(packing)
  result = cipher.update data.pack(packing)
  result.unpack packing
end

#packingObject


8
9
10
# File 'lib/rmega/crypto/aes.rb', line 8

def packing
  'l>*'
end