Class: Cript::Naive

Inherits:
Cripter show all
Defined in:
lib/cript/naive.rb

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

Methods inherited from Cripter

#echo

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(options = {})
  super
end

Instance Method Details

#commentObject



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(message)
  Base64::decode64(message).
    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(message)
  Base64::encode64(
    message.
    bytes.
    each_slice((size / 8) - 11).
    map { |chunk| @public_key.public_encrypt(chunk.pack('C*')) }.
    join)
end

#fingerprintObject



44
45
46
# File 'lib/cript/naive.rb', line 44

def fingerprint
  @opt[:fingerprint] || key_info[:fingerprint]
end

#inspectObject



32
33
34
# File 'lib/cript/naive.rb', line 32

def inspect
  "#<#{self.class.name} path=#{@opt[:public_key_path]}>"
end

#sizeObject



40
41
42
# File 'lib/cript/naive.rb', line 40

def size
  @opt[:size] || key_info[:size]
end

#typeObject



36
37
38
# File 'lib/cript/naive.rb', line 36

def type
  @opt[:type] || key_info[:type]
end