Class: Cryptonite::Coder
- Inherits:
-
Object
- Object
- Cryptonite::Coder
- Defined in:
- lib/cryptonite.rb
Overview
:nodoc:
Instance Method Summary collapse
-
#decrypt(value) ⇒ Object
(also: #load)
Decrypts a value with public key encryption.
-
#encrypt(value) ⇒ Object
(also: #dump)
Encrypts a value with public key encryption.
-
#initialize(key) ⇒ Coder
constructor
A new instance of Coder.
Constructor Details
#initialize(key) ⇒ Coder
Returns a new instance of Coder.
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)) 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)) end |