Class: RSA
- Inherits:
-
Object
- Object
- RSA
- Defined in:
- lib/crypto64.rb
Instance Method Summary collapse
-
#decrypt64(str) ⇒ Object
Decrypt and base64 decode data of arbitrary length.
-
#decrypt_block_size ⇒ Object
Calculate the block size when decrypting.
-
#encrypt64(str) ⇒ Object
Encrypt and base64 encode data of arbitrary length.
-
#encrypt_block_size ⇒ Object
Calculate the block size when encrypting.
-
#size ⇒ Object
Read the length of the private key.
Instance Method Details
#decrypt64(str) ⇒ Object
Decrypt and base64 decode data of arbitrary length.
37 38 39 40 41 42 43 44 45 |
# File 'lib/crypto64.rb', line 37 def decrypt64(str) dec = '' str = Base64.decode64(str) while str.length != 0 dec += self.private_decrypt(str[0..self.decrypt_block_size]) str = str[self.decrypt_block_size+1..-1] if str.length > self.decrypt_block_size end dec end |
#decrypt_block_size ⇒ Object
Calculate the block size when decrypting.
19 20 21 |
# File 'lib/crypto64.rb', line 19 def decrypt_block_size (size/8)-1 end |
#encrypt64(str) ⇒ Object
Encrypt and base64 encode data of arbitrary length.
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/crypto64.rb', line 24 def encrypt64(str) enc = '' while str.length > self.encrypt_block_size enc += self.public_encrypt(str[0..self.encrypt_block_size]) str = str[self.encrypt_block_size+1..-1] if str.length > self.encrypt_block_size end if str.length != 0 then enc += self.public_encrypt(str[0..self.encrypt_block_size]) end Base64.encode64(enc) end |
#encrypt_block_size ⇒ Object
Calculate the block size when encrypting.
14 15 16 |
# File 'lib/crypto64.rb', line 14 def encrypt_block_size (size/8)-12 end |
#size ⇒ Object
Read the length of the private key.
9 10 11 |
# File 'lib/crypto64.rb', line 9 def size /(\d+ bit)/.match(self.to_text)[0].split(' ')[0].to_i end |