com.zkteco:ddopen-securtiy

Communication security data encryption

License

License

GroupId

GroupId

com.zkteco
ArtifactId

ArtifactId

ddopen-securtiy
Last Version

Last Version

1.0.0
Release Date

Release Date

Type

Type

jar
Description

Description

com.zkteco:ddopen-securtiy
Communication security data encryption
Project URL

Project URL

https://github.com/larry0592/ddopen-security
Source Code Management

Source Code Management

https://github.com/larry0592/ddopen-security

Download ddopen-securtiy

How to add to project

<!-- https://jarcasting.com/artifacts/com.zkteco/ddopen-securtiy/ -->
<dependency>
    <groupId>com.zkteco</groupId>
    <artifactId>ddopen-securtiy</artifactId>
    <version>1.0.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.zkteco/ddopen-securtiy/
implementation 'com.zkteco:ddopen-securtiy:1.0.0'
// https://jarcasting.com/artifacts/com.zkteco/ddopen-securtiy/
implementation ("com.zkteco:ddopen-securtiy:1.0.0")
'com.zkteco:ddopen-securtiy:jar:1.0.0'
<dependency org="com.zkteco" name="ddopen-securtiy" rev="1.0.0">
  <artifact name="ddopen-securtiy" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.zkteco', module='ddopen-securtiy', version='1.0.0')
)
libraryDependencies += "com.zkteco" % "ddopen-securtiy" % "1.0.0"
[com.zkteco/ddopen-securtiy "1.0.0"]

Dependencies

compile (1)

Group / Artifact Type Version
commons-codec : commons-codec jar 1.10

test (2)

Group / Artifact Type Version
junit : junit jar 4.12
com.alibaba : fastjson jar 1.2.29

Project Modules

There are no modules declared in this project.

数据加解密及签名验签工具

面向开发者开源

使用说明详见 TestMe.java

    @Test
    public void testDecryptAndSignMsg(){
        String sToken = "LyENVdO33JcTxW";
        String sAppKey = "ww9c85c32b3dce1697";
        String sEncodingAESKey = "WiAqCmVluX9DHg7s7NloiQMW6imtx6BWt8ywhoyeiav";
        try {
            //请求方 Send
            MsgCrypt msgCrypt = new MsgCrypt(sToken,sEncodingAESKey,sAppKey);
            //时间戳
            String timeStamp = String.valueOf(System.currentTimeMillis());
            //生成随机数
            String nonce = StringUtils.getRandomStr(8);
            JSONObject  jsonObject = new JSONObject();
            jsonObject.put("sid","att.ems.transaction.upload");
            jsonObject.put("sn","10283012035");
            String jsonString = jsonObject.toJSONString();
            //原始业务请求包体加密
            String encryptJsonString = msgCrypt.encryptMsg(jsonString);
            //封装业务请求包体加密
            String reqData = "{ \"sys\":\"ww9c85c32b3dce1697\",\"data\":\""+encryptJsonString+"\"}";
            //生成签名
            String sourceSignature = SHA1.getSHA1(sToken, timeStamp, nonce, encryptJsonString);

            //接收方 Receive
            JSONObject requestBody = JSONObject.parseObject(reqData);
            String encrypt = requestBody.getString("data");

            String targetSignature  = SHA1.getSHA1(sToken, timeStamp, nonce, encrypt);
            assertEquals(sourceSignature, targetSignature);

            String decryptMsg = msgCrypt.decryptMsg(targetSignature,timeStamp,nonce,encrypt);
            assertEquals(decryptMsg, jsonString);
        }
        catch (AESException e) {
            e.printStackTrace();
        }
    }

Versions

Version
1.0.0