class OpenSSL::PKey::RSA

Encrypts and decrypts data of arbitrary length using RSA cyphers. Fixed and much faster fork of “crypto64” gem.

Constants

BIT_MATCHER

Matches the OpenSSH key bit count indicator.

Public Instance Methods

decrypt64(str) click to toggle source

Decrypt and base64 decode data of arbitrary length.

@param [String] str string for decrypting @return [String] decrypted string

# File lib/block64.rb, line 114
def decrypt64(str)
    dec = ''
    str = Base64.decode64(str)
    decrypt_block_size = self.decrypt_block_size

    while str.length > 0
        dec << self.private_decrypt(str[0..decrypt_block_size])
        if str.length > decrypt_block_size
            str.replace(str[decrypt_block_size + 1..-1])
        end
    end

    return dec
end
decrypt_block_size() click to toggle source

Calculate the block size when decrypting. @return [Integer] block size

# File lib/block64.rb, line 75
def decrypt_block_size
    if @decrypt_block_size.nil?
        @decrypt_block_size = (self.size / 8) - 1
    end

    return @decrypt_block_size
end
encrypt64(str) click to toggle source

Encrypt and base64 encode data of arbitrary length.

@param [String] str string for encrypting @return [String] encrypted string

# File lib/block64.rb, line 90
def encrypt64(str)
    enc = ''
    str = str.dup
    encrypt_block_size = self.encrypt_block_size

    while str.length > encrypt_block_size
        enc << self.public_encrypt(str[0..encrypt_block_size])
        str.replace(str[encrypt_block_size + 1..-1])
    end 

    if str.length > 0
        enc << self.public_encrypt(str[0..encrypt_block_size])
    end

    return Base64.encode64(enc)
end
encrypt_block_size() click to toggle source

Calculate the block size when encrypting. @return [Integer] block size

# File lib/block64.rb, line 62
def encrypt_block_size
    if @encrypt_block_size.nil?
        @encrypt_block_size = (self.size / 8) - 14
    end
    
    return @encrypt_block_size
end
size() click to toggle source

Read the length of the private key. @return [Integer] size (length) of the private key

# File lib/block64.rb, line 49
def size
    if @size.nil?
        @size = self.class::BIT_MATCHER.match(self.to_text)[1].to_i
    end

    return @size
end