阅读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月份产品更新__产品升级更新_移动安全-阿里云