Module: RockFintech::Encrypt::RSA

Defined in:
lib/rock_fintech/encrypt/rsa.rb

Class Method Summary collapse

Class Method Details

.decrypt(content, private_key) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rock_fintech/encrypt/rsa.rb', line 14

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

.encrypt(content, public_key) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/rock_fintech/encrypt/rsa.rb', line 6

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