Sha256: da4e602bbe99908883fcdb54230faba6bcc2b02ac1bd36ea4c92c06d7d6c3f75

Contents?: true

Size: 654 Bytes

Versions: 10

Compression:

Stored size: 654 Bytes

Contents

# coding: utf-8
module RockFintech
  module Encrypt
    module RSA

      def self.encrypt(content, public_key)
        content_str = ''
        content.scan(/.{1,100}/).each{ |str|
          content_str += public_key.public_encrypt(str)
        }
        Base64.strict_encode64(content_str)
      end

      def self.decrypt(content, private_key)
        content_str = Base64.strict_decode64(content)

        result_str = ''
        count = content_str.length / 256
        count.times.each{ |i|
          str = content_str[256*i, 256]
          result_str += private_key.private_decrypt(str)
        }

        result_str
      end

    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rock_fintech-0.10.0 lib/rock_fintech/encrypt/rsa.rb
rock_fintech-0.9.0 lib/rock_fintech/encrypt/rsa.rb
rock_fintech-0.8.0 lib/rock_fintech/encrypt/rsa.rb
rock_fintech-0.7.0 lib/rock_fintech/encrypt/rsa.rb
rock_fintech-0.6.0 lib/rock_fintech/encrypt/rsa.rb
rock_fintech-0.5.0 lib/rock_fintech/encrypt/rsa.rb
rock_fintech-0.4.0 lib/rock_fintech/encrypt/rsa.rb
rock_fintech-0.3.0 lib/rock_fintech/encrypt/rsa.rb
rock_fintech-0.2.0 lib/rock_fintech/encrypt/rsa.rb
rock_fintech-0.1.0 lib/rock_fintech/encrypt/rsa.rb