1、上云上平台接口规范版本修订批准记录【 历次版本修订记录,版本修订描述重要说明】提交日期 版本号 版本修订描述 修改人 备注2019-2-25 0.9 初稿 潘锡均2019-03-07 1.0 完善 杨钊目录1 接口功能说明1.1 概述1.1.1设计目的本规范明确上云上平台与相关的供应商的接口协议,为开发人员在进行接口设计、开发、使用过程中提供指导性意见。1.1.2加密协议使用 rsa 和 aes 相结合的方法加密接口返回数据, 上云上平台 通过请求头方式将公钥告知各个供应商接口,各个供应商接口返回数据时,需要通过 aes 算法对返回数据进行加密,同时也需要利用公钥,对 aes 密钥进行加密处理
2、返回。 相关代码见附录1.1.3编码格式统一是用 UTF-81.2 接口功能说明1.2.1使用说明用户 id、操作开始时间、操作结束时间,获取对应用户操作数据信息1.2.2请求1.2.2.1.1 请求参数统一请求头参数名称 说明 数据类型 可空Content-Type 固定数据类型 application/json; String Ncharset=UTF-8RSAPublicKey Rsa 公钥 String Ndata参数名称 说明 数据类型 可空userId 系统用户id ,可以多个,以逗号分割 String NbeginTime 操作时间开始yyyyMMddHHmmss long Ne
3、ndTime 操作时间结束yyyyMMddHHmmss long Y1.2.2.1.2 请求的 json 文档格式示例“beginTime“:20190306000000,“endTime“:20190307000000,“userId“:“13929537026,15994705655“1.2.2.1.3 请求的安全问题建议对固定 ip 做白名单处理(14.116.209.154, 122.13.1.153, 113.108.192.70)1.2.2.2返回1.2.2.2.1 返回参数参数名称 说明 数据类型 可空respCode “0”:成功,其它:失败。 String NrespMsg
4、返回值详细说明 String Ndata CryptoData 实体key String 加密的 Aes 密钥, Ncontent String 加密的返回数据(加密时请注意将返回结果转为 json字符串再做加密)Object N1.2.2.2.1.1data参数名称 说明 数据类型 可空companyId 企业 id,上云上平台和服务商统一 String YcompanyName 企业名称 String YuserId 用户id,企业自己填报的userId,泛指能够确定用户唯一的数据,如用户编码,电话号码等String NconnectMethod 链接方式,1物联网卡,2-手机app,3-
5、以太网long NmechineId 设备id,物联网卡中的设备号 String 如果链接方式是物联网卡,必填,其他类型,可以为空source 源地址,物联网卡中指卡号N手机app中指手机号以太网中指源iptarget 目标,目标ip或域名 NreqDuring 请求时长,服务端收到请求到返回数据的间隔时间,单位:毫秒,没有就不传,不做要求YcontLen 请求的文本的长度,服务端返回的数据的长度,单位,kb,没有就不传,不做要求YoperateTime 发生时间,格式yyyyMMddHHmmss long N1.2.2.2.2 返回 json 文档格式示例“respCode“: “0“,“r
6、espMsg“: “SUCCESS“,“data“: “key“: “bBw8sRM+zDqk7yJOAd0MmeckqoJveVQSlP6vcK0fs54vrDVmZdDpuu7VugW+JvjiP9pDEb/cUBYFjkwgXOFFkQ=“,“content“: “mk6xF16WxJAKwVBI5d7ULGmpajGuPEa59SRibZrGYrQ4gDmcir7/BKmWmsFt82VCnWAPItQz3nQRnnGDCSJ9tMxRBdkpXH76OwD7mKPV+s+alfaA+tuUtYSM/omTFHdc8kjxA6V+sFK5rDDtbV6amT+5nJwWYtlqtMHC
7、L34L1m6hE+agF5nTDvgaqhJzKkNwy2BecybxIeFo6f1LJXySv46q3ZvUmIBhwceTlnnWoWisBPAAbjR/rwhJv0oEc4nNKWRILOD83RQSs9YqV3noqd0Aq2UTm0lWIbBFO2tW0Wm9yC1Unfnb2e6MRdkLOK2FApp6Fk4+YEXK6NwmdrvhZEN7I7+mfM+kWEF45jW1vhzJUI3JqjaMZ2oLacl3shfnM79LQSjrJZqxHxzlMcCxd3HMgZlIe6Cw3JgEajsRmzs4Ni0nVg+uFgQUsJPufUq0mnWOAsH4mZoPnadC
8、030Q2gssRv7vSF6PG75WrnGzYdGlpOselJHlBWVfwrGP3jS4K7pp/Jczk/K6p54QRjKbsNQqInSCzpC8dBcQxZRB42KlwMiy7OKkek7Sslbc20LlANvaSFAkO481Az4g6KLlzkAtSrmCL3perrYDAHne6B0/6YiZ+nuq0GHkeKmDG9mfEDqU/wWZUAMGC+NG6T3uWp5wnT5fezuifKjNqaXRHWtbxjTeApmnLd8AQG1aTiHlURxwbOV3pnVrwrPiaNEsY332CMSqHoU6lMNz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6QvHQXEMWUQeNipcDIsuzipHpO0rJW3NtC5QDb2khQJDuPNQnM+IOii5c5ALUq5g8gApEyUewM94sxPVIh3A1“附录 A, package com.cdc.workcloud.manage.util;import mon.util.JsonMapper;import mons.codec.binary.Base64;import org.springframework.stereotype.Component;import org.spring
31、framework.util.Base64Utils;import javax.crypto.Cipher;import java.security.*;import java.security.interfaces.RSAPrivateKey;import java.security.interfaces.RSAPublicKey;import java.security.spec.PKCS8EncodedKeySpec;import java.security.spec.X509EncodedKeySpec;import java.util.Date;import java.util.Ha
32、shMap;import java.util.Map;/* 非对称加密算法 RSA 算法组件* 非对称算法一般是用来传送对称加密算法的密钥来使用的,相对于 DH 算法, RSA 算法只需要一方构造密钥,不需要* 大费周章的构造各自本地的密钥对了。 DH 算法只能算法非对称算法的底层实现。而 RSA 算法算法实现起来较为简单* author kongqz*/Componentpublic class RSACoder /非对称密钥算法public static final String KEY_ALGORITHM = “RSA“;/* 密钥长度, DH 算法的默认密钥长度是 1024* 密钥长度
33、必须是 64 的倍数,在 512 到 65536 位之间*/private static final int KEY_SIZE = 512;/公钥private static final String PUBLIC_KEY = “RSAPublicKey“;/私钥private static final String PRIVATE_KEY = “RSAPrivateKey“;/* 初始化密钥对* return Map 甲方密钥的 Map*/public static Map initKey() throws Exception /实例化密钥生成器KeyPairGenerator keyPai
34、rGenerator = KeyPairGenerator.getInstance(KEY_ALGORITHM);/初始化密钥生成器keyPairGenerator.initialize(KEY_SIZE);/生成密钥对KeyPair keyPair = keyPairGenerator.generateKeyPair();/甲方公钥RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();/甲方私钥RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();/将密
35、钥存储在 map 中Map keyMap = new HashMap();keyMap.put(PUBLIC_KEY, publicKey);keyMap.put(PRIVATE_KEY, privateKey);return keyMap;/* 私钥加密* param data 待加密数据* param key 密钥* return byte 加密数据*/public static byte encryptByPrivateKey(byte data, String key) throws Exception byte keyBytes = Base64Utils.decodeFromStr
36、ing(key);/取得私钥PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);/生成私钥PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec);/数据加密Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm();cipher.init(Cipher.
37、ENCRYPT_MODE, privateKey);return cipher.doFinal(data);/* 公钥加密* param data 待加密数据* param key 密钥* return byte 加密数据*/public static byte encryptByPublicKey(byte data, String key) throws Exception byte keyBytes = Base64Utils.decodeFromString(key);/实例化密钥工厂KeyFactory keyFactory = KeyFactory.getInstance(KEY_
38、ALGORITHM);/初始化公钥/密钥材料转换X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);/产生公钥PublicKey pubKey = keyFactory.generatePublic(x509KeySpec);/数据加密Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm();cipher.init(Cipher.ENCRYPT_MODE, pubKey);return cipher.doFinal(data);/* 私钥解密* par
39、am data 待解密数据* param key 密钥* return byte 解密数据*/public static byte decryptByPrivateKey(byte data, String key) throws Exception byte keyBytes = Base64Utils.decodeFromString(key);/取得私钥PKCS8EncodedKeySpec pkcs8KeySpec = new PKCS8EncodedKeySpec(keyBytes);KeyFactory keyFactory = KeyFactory.getInstance(KEY
40、_ALGORITHM);/生成私钥PrivateKey privateKey = keyFactory.generatePrivate(pkcs8KeySpec);/数据解密Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm();cipher.init(Cipher.DECRYPT_MODE, privateKey);return cipher.doFinal(data);/* 公钥解密* param data 待解密数据* param key 密钥* return byte 解密数据*/public static byte d
41、ecryptByPublicKey(byte data, String key) throws Exception byte keyBytes = Base64Utils.decodeFromString(key);/实例化密钥工厂KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM);/初始化公钥/密钥材料转换X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes);/产生公钥PublicKey pubKey = keyFactory.generate
42、Public(x509KeySpec);/数据解密Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm();cipher.init(Cipher.DECRYPT_MODE, pubKey);return cipher.doFinal(data);/* 取得私钥* param keyMap 密钥 map* return byte 私钥*/public static String getPrivateKey(Map keyMap) Key key = (Key) keyMap.get(PRIVATE_KEY);return Base6
43、4Utils.encodeToString(key.getEncoded();/* 取得公钥* param keyMap 密钥 map* return byte 公钥*/public static String getPublicKey(Map keyMap) throws Exception Key key = (Key) keyMap.get(PUBLIC_KEY);return Base64Utils.encodeToString(key.getEncoded();package com.cdc.workcloud.manage.util;import java.security.Key
44、;import java.util.UUID;import javax.crypto.Cipher;import javax.crypto.spec.SecretKeySpec;import sun.misc.BASE64Decoder;import sun.misc.BASE64Encoder;public class AESSecurityUtil / 加密算法/* 指定加密算法为 RSA */private static final String ALGORITHM = “AES“;/ 加密密钥/ private static final byte keyValue = new byte
45、 T, h, e,/ B,e, s, t, S, e, c, r, e, t, K, e, y ;/ 16 位的加密密钥/ private byte keyValue;/* 用来进行加密的操作* param* return* throws Exception*/public static String encrypt(String keyString, String data)throws Exception Key key = generateKey(keyString);Cipher c = Cipher.getInstance(ALGORITHM);c.init(Cipher.ENCRY
46、PT_MODE, key);byte encVal = c.doFinal(data.getBytes();String encryptedValue = new BASE64Encoder().encode(encVal);return encryptedValue;/* 用来进行解密的操作* param encryptedData* return* throws Exception*/public static String decrypt(String keyString, String encryptedData) throws Exception Key key = generate
47、Key(keyString);Cipher c = Cipher.getInstance(ALGORITHM);c.init(Cipher.DECRYPT_MODE, key);byte decordedValue = new BASE64Decoder().decodeBuffer(encryptedData);byte decValue = c.doFinal(decordedValue);String decryptedValue = new String(decValue);return decryptedValue;public static String generateKeySt
48、ring()/必须长度为 16return UUID.randomUUID().toString().replaceAll(“-“, “).substring(0, 16);/* 根据密钥和算法生成 Key* return* throws Exception*/private static Key generateKey(String keyString) throws Exception Key key = new SecretKeySpec(keyString.getBytes(), ALGORITHM);return key;public static void main(String args) throws ExceptionString keyString = generateKeyString();/ String keyString = “1234567890123456“;System.out.println(“密钥: “ + keyString);String source = “恭喜发财!“;/ 要加密的字符串System.out.println(“准备用密钥加密的字符串为: “ + source);String cryptograph = encrypt