Class: Cryptonite::Coder

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

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ Coder

Returns a new instance of Coder.

Raises:

  • (ArgumentError)


71
72
73
74
# File 'lib/cryptonite.rb', line 71

def initialize(key)
  raise ArgumentError unless key.is_a?(::OpenSSL::PKey::RSA)
  @key = key
end

Instance Method Details

#decrypt(value) ⇒ Object Also known as: load

Decrypts a value with public key encryption. Keys should be defined in environment.



85
86
87
# File 'lib/cryptonite.rb', line 85

def decrypt(value)
  @key.private_decrypt(Base64.decode64(value)) if value
end

#encrypt(value) ⇒ Object Also known as: dump

Encrypts a value with public key encryption. Keys should be defined in environment.



78
79
80
# File 'lib/cryptonite.rb', line 78

def encrypt(value)
  Base64.encode64(@key.public_encrypt(value)) if value
end