閱讀347 返回首頁    go 財經資訊


服務端驗簽及加解密__安全組件教程_移動安全-阿裏雲

1、內容簡介

本文檔是針對聚安全安全組件服務端jar包的使用說明,主要包括簽名校驗和加解密兩部分。

2、準備工作

以下麵的demo程序為例。

首先,您需要拷貝signcheckExternal_3.0.10.jar到lib目錄,再拷貝conf.properties文件到conf目錄。

3、簽名校驗

3.1【接口名稱】

  1. public String check(String type, String input, String appKey,
  2. String sign)

3.2【作用】

根據輸入的type,input以及appKey來驗證sign是否正確

3.3【參數】

type:簽名算法類型, 使用hmacsha1 字符串。

input: 原始輸入內容

appKey:加密使用的key

sign: 簽名內容

3.4【返回值】

true : 驗證簽名結果正確

false: 驗證簽名結果錯誤

no appsecret for appkey: 輸入的appKey不正確,請使用從官網獲得的正確appKey。

invalid check type:簽名算法類型不正確,隻能使用hmacsha1 字符串。

4、字符串解密接口

4.1【接口名稱】

  1. public String decrypt(String content, String appKey)

4.2【作用】

對輸入內容content進行解密得到對應的明文信息

4.3【參數】

content:輸入密文

appKey:加密使用的appKey

4.4【返回值】

解密後的明文或者null

5、二進製解密接口

5.1【接口名稱】

  1. public byte[] decrypt(byte[] content, String appKey)

5.2【作用】

對輸入內容content進行解密得到對應的明文信息

5.3【參數】

content:輸入密文

appKey:加密使用的appKey

5.4【返回值】

解密後的明文或者null

6、字符串加密接口

6.1【接口名稱】

  1. public String encrypt(String content, String appKey)

6.2【作用】

對輸入內容content進行加密得到對應的加密信息

6.3【參數】

content:輸入明文

appKey:加密使用的appKey

6.4【返回值】

加密後的密文或者null

7、二進製加密接口

7.1【接口名稱】

  1. public byte[] encrypt(byte[] content, String appKey)

7.2【作用】

對輸入內容content進行加密得到對應的加密信息

7.3【參數】

content:輸入明文

appKey:加密使用的appKey

7.4【返回值】

加密後的密文或者null

8、以下是驗簽和加解密的使用示例

  1. import com.taobao.wsg.signcheck.CheckWithConfig;
  2. public class Demo {
  3. public static void main(String[] args) {
  4. String configFilePath = "conf/conf.properties";
  5. CheckWithConfig checkWithConfig = new CheckWithConfig(configFilePath);
  6. try {
  7. /*
  8. * test check method
  9. */
  10. String type = "hmacsha1";
  11. String input = "&to&sign&test&tosign&def";
  12. String appKey = "k1";
  13. String sign = "81c3c1918149e05dbce3ff96054984952f9d2a4a";
  14. String result = checkWithConfig.check(type, input ,appKey ,sign);
  15. System.out.println("check result is " + result);
  16. /*
  17. * test encrypt and decrypt
  18. */
  19. String encryptResult = checkWithConfig.encrypt("helloword", appKey);
  20. System.out.println("encryptResult is " + encryptResult);
  21. String decryptResult = checkWithConfig.decrypt("f75KZo4tpMyAu066HiqrXA==", appKey);
  22. System.out.println("decryptResult is " + decryptResult);
  23. } catch (Exception e) {
  24. System.out.println(e);
  25. }
  26. }
  27. }

最後更新:2016-12-13 15:23:00

  上一篇:go 接口文檔__Android_安全組件教程_移動安全-阿裏雲
  下一篇:go 10月份產品更新__產品升級更新_移動安全-阿裏雲