陈福行 пре 4 година
родитељ
комит
0602b75873
4 измењених фајлова са 241 додато и 15 уклоњено
  1. 6
    0
      .idea/vcs.xml
  2. 89
    0
      README.md
  3. 98
    0
      README_zh.md
  4. 48
    15
      app/src/main/java/com/elinkthings/ailinksecrettooldemo/AnalyticalDataUtil.java

+ 6
- 0
.idea/vcs.xml Прегледај датотеку

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

+ 89
- 0
README.md Прегледај датотеку

@@ -0,0 +1,89 @@
# AILinkSecretToolDemo_Android


### 1、Usage description
AILinkSecretAndroid is a Bluetooth encryption and decryption toolkit developed using java/c++ on the Android platform. The development kit can scan and connect to smart devices using AILink Bluetooth modules, and is responsible for the handshake between App and Bluetooth modules and the encryption and decryption of A7 data

### 2、Necessary condition
+ 1. Acquired AILink Bluetooth communication protocol
+ 2. Have smart devices that support AILink Bluetooth module
+ 3. Have knowledge of Android native development and debugging

### 3、Applicable conditions
+ 1. Develop your own native platform app
+ 2. Use RN, Uniapp, Flutter and other cross-platform technologies to develop apps

### 四、Import SDK

```
1. Add the JitPack repository to your build file
Add this to the root build.gradle at the end of the repository:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
2. Add dependencies
dependencies {
...
implementation 'com.github.elinkthings:AILinkSecretAndroid:1.0.0'

}
3.Configure java1.8 in gradle
android {
...
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
repositories {
flatDir {
dirs 'libs'
}
}
}

```
### 4、SDK provides method classes AnalyticalDataUtil.java
```



/**
The app sends this A6 data to actively start handshake with ble, and the return byte[] needs to be sent to ble actively
*/
byte[] initHandshakeArr();

/**
If you can get BluetoothGatt, it is easier to call the sendHandshake method to send a handshake
*/
void sendHandshake(final BluetoothGatt gatt);

/**
This method encrypts the A6 data of the ble test app and sends the app to the device, otherwise the device will disconnect the app and return byte[] and need to actively send it to ble
*/
byte[] initHandshakeArrPwd(byte[] hex);


/**
If you can get BluetoothGatt, it is easier to call the sendHandshakePwd method to send a handshake
*/
void sendHandshakePwd(byte[] hex);

/**
A7 data decryption method
*/
byte[] mcuDecrypt(byte[] hex, String mac);

/**
A7 data encryption method, cid is the product ID, and the ble protocol will include
*/
byte[] mcuEncrypt(int cid, String mac, byte[] payload);


```

### 5、How to use

For specific usage, please refer to AILinkSecretToolDemo

+ 98
- 0
README_zh.md Прегледај датотеку

@@ -0,0 +1,98 @@
# AILinkSecretToolDemo_Android


### 一、用途说明
AILinkSecretAndroid是在Android平台使用java/c++开发的蓝牙加解密工具包,该开发工具包能够扫描、连接使用AILink蓝牙模组的智能设备,负责App与蓝牙模组之间的握手与A7数据的加解密。

### 二、必备条件
+ 1. 已获取AILink蓝牙通讯协议
+ 2. 拥有支持AILink蓝牙模块的智能设备
+ 3. 具备Android原生开发和调试知识

### 三、适用场景
+ 1. 开发自己的原生平台app
+ 2. 使用RN、Uniapp、Flutter等跨平台技术开发app

### 四、导入SDK

```

1.将JitPack存储库添加到您的构建文件中
将其添加到存储库末尾的root build.gradle中:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

2.添加依赖项
dependencies {
implementation 'com.github.elinkthings:AILinkSecretAndroid:1.0.0'//加解密库
}

3.在gradle中配置java1.8
android {
...
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
repositories {
flatDir {
dirs 'libs'
}
}
}

```
### 四、SDK提供接口 AnalyticalDataUtil.java
```



/**
app发送此A6数据主动开始与ble进行握手,返回byte[]需要主动发送给ble
*/
byte[] initHandshakeArr();

/**
如果可以拿到BluetoothGatt,可调用sendHandshake方法发送握手更简单
*/
void sendHandshake(final BluetoothGatt gatt);

/**
此方法将ble检验app的A6数据进行加密,app发给设备,否则设备将断开app,返回byte[]需要主动发送给ble
*/
byte[] initHandshakeArrPwd(byte[] hex);


/**
如果可以拿到BluetoothGatt,可调用sendHandshakePwd方法发送握手更简单
*/
void sendHandshakePwd(byte[] hex);

/**
A7数据解密方法
*/
byte[] mcuDecrypt(byte[] hex, String mac);

/**
A7数据加密方法,cid为产品ID,ble协议中会包含
*/
byte[] mcuEncrypt(int cid, String mac, byte[] payload);


```

### 五、使用方法

具体用法详见AILinkSecretToolDemo









+ 48
- 15
app/src/main/java/com/elinkthings/ailinksecrettooldemo/AnalyticalDataUtil.java Прегледај датотеку

@@ -111,7 +111,7 @@ public class AnalyticalDataUtil {
if (hex[0] == CmdConfig.SEND_BLE_START && hex[2] == CmdConfig.SET_HANDSHAKE) {
//是握手数据
byte[] bleDataHandshake = AiLinkBleCheckUtil.returnHandshakeDataFormat(hex);
sendHandshakePwd( bleDataHandshake);
sendHandshakePwd(bleDataHandshake);
} else {
protocolNotifyData(mac, uuid, hex);
}
@@ -121,7 +121,7 @@ public class AnalyticalDataUtil {
if (hex[0] == CmdConfig.SEND_BLE_START && hex[2] == CmdConfig.SET_HANDSHAKE) {
//是握手数据
byte[] bleDataHandshake = AiLinkBleCheckUtil.returnHandshakeDataFormat(hex);
sendHandshakePwd( bleDataHandshake);
sendHandshakePwd(bleDataHandshake);
} else {
protocolNotifyData(mac, uuid, hex);
}
@@ -153,15 +153,10 @@ public class AnalyticalDataUtil {
break;

case CmdConfig.SEND_MCU_START:
payload = AiLinkBleCheckUtil.returnMcuDataFormat(hex);
if (payload != null && payload.length >= 1) {
byte[] CID = new byte[]{hex[1], hex[2]};
byte[] data;
data = AiLinkBleCheckUtil.mcuEncrypt(CID, payload, mac);
if (data.length > 0) {
if (mOnAnalyticalListener != null) {
mOnAnalyticalListener.onAnalyticalData(mac, uuid, data);
}
byte[] bytes = mcuDecrypt(hex, mac);
if (bytes.length > 0) {
if (mOnAnalyticalListener != null) {
mOnAnalyticalListener.onAnalyticalData(mac, uuid, bytes);
}
}
break;
@@ -249,7 +244,7 @@ public class AnalyticalDataUtil {
/**
* 密文握手
*/
public void sendHandshakePwd( byte[] hex) {
public void sendHandshakePwd(byte[] hex) {
byte[] bytes = initHandshakeArrPwd(hex);
if (bytes != null) {
sendCmd(bytes);
@@ -258,19 +253,19 @@ public class AnalyticalDataUtil {

private synchronized void sendCmd(final byte[] bytes) {
if (bytes != null) {

mHandler.post(new Runnable() {
@Override
public void run() {
SystemClock.sleep(100);
BluetoothGattService mGattService = MyBleDeviceUtils.getService(mBluetoothGatt, BleConfig.UUID_SERVER_AILINK);
if (mGattService != null) {
BluetoothGattCharacteristic mCharacteristic = MyBleDeviceUtils.getServiceWrite(mGattService, BleConfig.UUID_WRITE_NOTIFY_AILINK);
BluetoothGattCharacteristic mCharacteristic = MyBleDeviceUtils
.getServiceWrite(mGattService, BleConfig.UUID_WRITE_NOTIFY_AILINK);
if (mCharacteristic != null) {
mCharacteristic.setValue(bytes);
mCharacteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE);
boolean b = mBluetoothGatt.writeCharacteristic(mCharacteristic);
Log.i("AnalyticalDataUtil","send:"+b);
Log.i("AnalyticalDataUtil", "send:" + b);
}
}
}
@@ -319,6 +314,44 @@ public class AnalyticalDataUtil {

//---------------------握手指令发送校验 end-------------


/**
* 解密A7数据
*
* @param hex byte[]
* @param mac mac
* @return byte[]
*/
private byte[] mcuDecrypt(byte[] hex, String mac) {
byte[] data = AiLinkBleCheckUtil.returnMcuDataFormat(hex);
if (data != null && data.length >= 1) {
byte[] CID = new byte[]{hex[1], hex[2]};
data = AiLinkBleCheckUtil.mcuEncrypt(CID, data, mac);
}
return data;
}


/**
* 加密A7数据
*
* @param cid cid
* @param mac mac
* @param payload byte[]
* @return byte[]
*/
private byte[] mcuEncrypt(int cid, String mac, byte[] payload) {
byte[] data = null;
if (payload != null && payload.length >= 1) {
byte[] CID = new byte[2];
CID[0] = (byte) ((cid >> 8) & 0xff);
CID[1] = (byte) (cid);
data = AiLinkBleCheckUtil.mcuEncrypt(CID, payload, mac);
}
return data;
}


public void close() {
if (mBluetoothGatt != null) {
mBluetoothGatt.disconnect();

Loading…
Откажи
Сачувај