Class: RedisRpc::Base64Aes

Inherits:
Object
  • Object
show all
Defined in:
lib/redis_rpc/parser.rb

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Base64Aes

Returns a new instance of Base64Aes.



28
29
30
31
32
# File 'lib/redis_rpc/parser.rb', line 28

def initialize(key)
  @key = key
  @cipher = OpenSSL::Cipher::AES.new(128, :CBC).encrypt
  @decipher = OpenSSL::Cipher::AES.new(128, :CBC).decrypt
end

Instance Method Details

#decrypt(encrypted) ⇒ Object



37
38
39
40
# File 'lib/redis_rpc/parser.rb', line 37

def decrypt(encrypted)
  @decipher.key = @key
  @decipher.update(decode64(encrypted)) + @decipher.final
end

#encrypt(data) ⇒ Object



33
34
35
36
# File 'lib/redis_rpc/parser.rb', line 33

def encrypt(data)
  @cipher.key = @key
  encode64(@cipher.update(data) + @cipher.final)
end