add DES encrypt
This commit is contained in:
parent
0e7aa6249b
commit
c6884b2db2
|
@ -1,4 +1,5 @@
|
|||
require 'net/http'
|
||||
require "base64"
|
||||
module AsiaSyncPlugin
|
||||
class SafeHash < Hash
|
||||
attr_accessor :duplicate_check_off
|
||||
|
@ -10,6 +11,8 @@ module AsiaSyncPlugin
|
|||
end
|
||||
end
|
||||
end
|
||||
IV = [0x12, 0x34, 0x56, 0x84, 0x9b, 0xab, 0xcd, 0xef].pack('C*')
|
||||
KEY = "Tch#^837".bytes.pack('C*')
|
||||
#ok 期刊論文/Journal Papers
|
||||
#ok 專書/Books
|
||||
#ok 專書論文/Book Chapters
|
||||
|
@ -372,7 +375,15 @@ namespace :sync_asia_personal_plugins do
|
|||
def get_sync_data(user_id)
|
||||
uri = URI.parse("https://webap.asia.edu.tw/cfd2020/API/Research/Load")
|
||||
@read_timeout = 300
|
||||
res = net_http_get_response(uri + "?#{{:id=> user_id}.to_query}")
|
||||
data = "id=#{user_id}"
|
||||
cipher = OpenSSL::Cipher::Cipher.new("des").encrypt.tap do |obj|
|
||||
obj.iv = IV
|
||||
obj.key = KEY
|
||||
end
|
||||
cipher.update(data)
|
||||
encrypt = cipher.final()
|
||||
encrypt_base64 = Base64.encode64(encrypt).strip
|
||||
res = net_http_get_response(uri + "?#{encrypt_base64}")
|
||||
return JSON.parse(res.body,{object_class: AsiaSyncPlugin::SafeHash})
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue