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.

Instance Method Summary collapse

Methods inherited from Cripter

#echo, #initialize, #inspect

Constructor Details

This class inherits a constructor from Cript::Cripter

Instance Method Details

#decrypt(message) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/cript/naive.rb', line 22

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



13
14
15
16
17
18
19
20
# File 'lib/cript/naive.rb', line 13

def encrypt(message)
  Base64::encode64(
    message.
    bytes.
    each_slice((size / 8) - 11).
    map { |chunk| @public_key.public_encrypt(chunk.pack('C*')) }.
    join)
end