為了保證http請求資料的安全性,防篡改性以及用於標示機構身份,防止偽造的介面請求。
一、md5算hash方式:
加密規則可以根據雙方介面協商定義,示例如下:
1. 引數說明2. 加密規則
(1)將篩選的引數按照第乙個字元的鍵值ascii碼遞增排序(字母公升序排序),如果遇到相同字元則按照第二個字元的鍵值ascii碼遞增排序,以此類推。
(2)將排序後的引數與其對應值,組合成「引數=引數值」的格式,並且把這些引數用&字元連線起來,此時生成的字串為待簽名字串
(3)生成簽名:sign = md5(待簽名字串)
3. 處理流程4.驗證方式
/**md5雜湊處理引數
* @param param 引數列表
* @param orgsecretkey 機構api私鑰
*/public
static map
hash
(map param,string orgsecretkey)
param.
put(
"hash"
,md5
(sb.
tostring()
+ orgsecretkey,
"utf-8").
touppercase()
);return param;
}/**
* md5
* @param msg
* @param charset
* @return
*/public
static string md5
(string msg, string charset)
catch
(nosuchalgorithmexception
| unsupportedencodingexception ex)
return"";
}/**
* bytes to hex string
* @param arraybytes
* @return
*/public
static string byts2hexstr
(byte[
] arraybytes)
return sb.
tostring()
;}
二、rsa方式:數字簽名:帶有金鑰(公鑰、私鑰)的訊息摘要演算法(使用私鑰進行簽名,使用公鑰進行驗證)
數字簽名演算法:rsa(經典演算法:md5withrsa和sha256withrsa)
數字簽名特性: 驗證資料完整性、 認證資料**、抗否認性
具體步驟分為兩大步:
1.傳送方生成金鑰對+公布公鑰給服務方
2.傳送方私鑰加密生成簽名+服務方公鑰驗證處理請求
**思路:
1、傳送方生成公鑰(pubk)私鑰(prik)
2、傳送方根據私鑰(prik)將傳送內容明文(content1)進行加密得到密文(content2)
3、根據私鑰(prik)將密文(content2)進行加簽生成數字簽名sign
4、傳送方將密文(content2)+公鑰(pubk)+數字簽名sign傳送給服務方
5、服務方根據密文(content2)+公鑰(pubk)+數字簽名sign進行驗籤
6、如果驗籤成功根據公鑰(pubk)對密文進行解密,獲取所需請求引數
核心**rsautils
.
/*
* * 1生成金鑰對(公鑰和私鑰)
* *
* @return
* @throws exception
*/public
static map
genkeypair
() throws exception
/** * * 獲取私鑰
* *
* @param keymap 金鑰對
* @return
* @throws exception
*/public
static string getprivatekey
(map keymap)
throws exception
/** * * 獲取公鑰
* *
* @param keymap 金鑰對
* @return
* @throws exception
*/public
static string getpublickey
(map keymap)
throws exception
/** * * 2私鑰加密
* *
* @param data 源資料
* @param privatekey 私鑰(base64編碼)
* @return
* @throws exception
*/public
static byte[
]encryptbyprivatekey
(byte[
] data, string privatekey)
throws exception
else
out.
write
(cache,
0, cache.length)
; i++
; offset = i *
max_encrypt_block;}
byte[
] encrypteddata = out.
tobytearray()
; out.
close()
;return encrypteddata;
}/**
* * 3用私鑰對資訊生成數字簽名
* *
* @param data 已加密資料
* @param privatekey 私鑰(base64編碼)
* * @return
* @throws exception
*/public
static string sign
(byte[
] data, string privatekey) throws exception
/** * * 4校驗數字簽名
* *
* @param data 已加密資料
* @param publickey 公鑰(base64編碼)
* @param sign 數字簽名
* * @return
* @throws exception
* */
public
static boolean verify
(byte[
] data, string publickey, string sign)
throws exception
/** * * 5公鑰解密
* *
* @param encrypteddata 已加密資料
* @param publickey 公鑰(base64編碼)
* @return
* @throws exception
*/public
static byte[
]decryptbypublickey
(byte[
] encrypteddata, string publickey)
throws exception
else
out.
write
(cache,
0, cache.length)
; i++
; offset = i *
max_decrypt_block;}
byte[
] decrypteddata = out.
tobytearray()
; out.
close()
;return decrypteddata;
}
部分參考: 介面測試(三)介面測試工具
介面測試工具分類 抓取介面,測試介面 抓包工具分析與抉擇 1.httpwatch ie firefox瀏覽器的外掛程式,較少選擇 2.wireshark 功能齊全龐大,tcp udp都可抓取到,抓取經過電腦的所有請求,看資料比較麻煩,需要新增表示式過濾,一般也不選用 3.fiddler 輕量級,只記...
軟體測試 三 介面測試
有軟體的地方就有介面,就會有介面測試。介面測試是軟體測試中,最多,最繁瑣,最簡單的測試。尤其在本地化測試 多國語言測試 中,有很多的介面測試。介面測試,也叫ui測試 user inte ce testing 本文介紹一些常見的介面測試,以及描述介面bug時所用的術語。閱讀目錄 介面測試的目的 介面測...
Cobaltstrike學習(三)介面功能
1.新建連線 2.斷開當前連線 3.4.轉換檢視模式為圖示模式 像網路拓撲一樣 5.轉換檢視模式為詳細會話列表模式 6.轉換檢視模式為目標列表 7.憑據資訊 9.記錄鍵盤 10.螢幕截圖 已上線的機器的 11.生成無狀態beacon後門 13.office巨集攻擊 14.生成指令碼通過web傳遞 利...