From c6884b2db2ef66c2f47f1a50ecb8833696c7b638 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B1=E5=8D=9A=E4=BA=9E?= Date: Sat, 18 Dec 2021 16:01:23 +0800 Subject: [PATCH] add DES encrypt --- lib/tasks/sync_asia_personal_data_tasks.rake | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/tasks/sync_asia_personal_data_tasks.rake b/lib/tasks/sync_asia_personal_data_tasks.rake index 81f601c..c02c116 100644 --- a/lib/tasks/sync_asia_personal_data_tasks.rake +++ b/lib/tasks/sync_asia_personal_data_tasks.rake @@ -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 \ No newline at end of file