Class: Crypto::Key
- Inherits:
-
Object
- Object
- Crypto::Key
- Defined in:
- lib/crypto.rb
Class Method Summary collapse
Instance Method Summary collapse
- #decrypt(text) ⇒ Object
- #encrypt(text) ⇒ Object
-
#initialize(data) ⇒ Key
constructor
A new instance of Key.
- #key_type ⇒ Object
- #private? ⇒ Boolean
- #public? ⇒ Boolean
Constructor Details
#initialize(data) ⇒ Key
Returns a new instance of Key.
14 15 16 17 |
# File 'lib/crypto.rb', line 14 def initialize(data) @public = (data =~ /^-----BEGIN (RSA|DSA) PRIVATE KEY-----$/).nil? @key = OpenSSL::PKey::RSA.new(data) end |
Class Method Details
.from_file(filename) ⇒ Object
19 20 21 |
# File 'lib/crypto.rb', line 19 def self.from_file(filename) self.new File.read( filename ) end |
Instance Method Details
#decrypt(text) ⇒ Object
27 28 29 |
# File 'lib/crypto.rb', line 27 def decrypt(text) @key.send("#{key_type}_decrypt", text) end |
#encrypt(text) ⇒ Object
23 24 25 |
# File 'lib/crypto.rb', line 23 def encrypt(text) @key.send("#{key_type}_encrypt", text) end |
#key_type ⇒ Object
39 40 41 |
# File 'lib/crypto.rb', line 39 def key_type @public ? :public : :private end |
#private? ⇒ Boolean
31 32 33 |
# File 'lib/crypto.rb', line 31 def private? !@public end |
#public? ⇒ Boolean
35 36 37 |
# File 'lib/crypto.rb', line 35 def public? @public end |