Class: Ktct::Wangjinshe

Inherits:
Thor
  • Object
show all
Includes:
Config, Cryptable
Defined in:
lib/ktct/wangjinshe.rb

Instance Attribute Summary

Attributes included from Cryptable

#key

Instance Method Summary collapse

Methods included from Cryptable

#crypt, #max_decrypt_block_size, #max_encrypt_block_size, #modulus_byte_size, #reset_key, #ssign, #stupid_decrypt, #stupid_decrypt_batch, #stupid_encrypt, #stupid_encrypt_batch, #sverify

Methods included from Config

#config

Instance Method Details

#decrypt(data = nil) ⇒ Object



20
21
22
23
# File 'lib/ktct/wangjinshe.rb', line 20

def decrypt(data = nil)
  reset_key(config['client_private_key_path'])
  puts private_decrypt(Base64.strict_decode64((data || STDIN.read).gsub(/\n/, '')))
end

#encrypt(data = nil) ⇒ Object



14
15
16
17
# File 'lib/ktct/wangjinshe.rb', line 14

def encrypt(data = nil)
  reset_key(config['server_public_key_path'])
  puts URI::encode_www_form_component(Base64.strict_encode64(public_encrypt(data || STDIN.read)).scan(/.{1,76}/).join("\n"))
end

#sign(data = nil) ⇒ Object



26
27
28
29
# File 'lib/ktct/wangjinshe.rb', line 26

def sign(data = nil)
  reset_key(config['client_private_key_path'])
  puts URI::encode_www_form_component(Base64.strict_encode64(key.sign('sha1', data || STDIN.read)).scan(/.{1,76}/).join("\n"))
end