Class: Cript::Naive
Overview
Cript::Naive uses rsa keys to encrypt data. It allows you to easily encrypt and decrypt strings. Performance is poor because rsa public keys were not meant to do this.
Defined Under Namespace
Classes: Error
Instance Method Summary collapse
- #comment ⇒ Object
- #decrypt(message) ⇒ Object
- #encrypt(message) ⇒ Object
- #fingerprint ⇒ Object
-
#initialize(options = {}) ⇒ Naive
constructor
Options: public_key_content private_key_content.
- #inspect ⇒ Object
- #size ⇒ Object
- #type ⇒ Object
Methods inherited from Cripter
Constructor Details
#initialize(options = {}) ⇒ Naive
Options: public_key_content private_key_content
public_key_path private_key_path
passphrase
type size fingerprint comment
28 29 30 |
# File 'lib/cript/naive.rb', line 28 def initialize( = {}) super end |
Instance Method Details
#comment ⇒ Object
48 49 50 |
# File 'lib/cript/naive.rb', line 48 def comment @opt[:comment] || key_info[:comment] end |
#decrypt(message) ⇒ Object
61 62 63 64 65 66 67 |
# File 'lib/cript/naive.rb', line 61 def decrypt() Base64::decode64(). bytes. each_slice(size / 8). map { |chunk| @private_key.private_decrypt(chunk.pack('C*')) }. join end |
#encrypt(message) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/cript/naive.rb', line 52 def encrypt() Base64::encode64( . bytes. each_slice((size / 8) - 11). map { |chunk| @public_key.public_encrypt(chunk.pack('C*')) }. join) end |
#fingerprint ⇒ Object
44 45 46 |
# File 'lib/cript/naive.rb', line 44 def fingerprint @opt[:fingerprint] || key_info[:fingerprint] end |
#inspect ⇒ Object
32 33 34 |
# File 'lib/cript/naive.rb', line 32 def inspect "#<#{self.class.name} path=#{@opt[:public_key_path]}>" end |
#size ⇒ Object
40 41 42 |
# File 'lib/cript/naive.rb', line 40 def size @opt[:size] || key_info[:size] end |
#type ⇒ Object
36 37 38 |
# File 'lib/cript/naive.rb', line 36 def type @opt[:type] || key_info[:type] end |