<?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||
<project version="4"> | <project version="4"> | ||||
<component name="CompilerConfiguration"> | <component name="CompilerConfiguration"> | ||||
<bytecodeTargetLevel target="9" /> | |||||
<bytecodeTargetLevel target="1.8" /> | |||||
</component> | </component> | ||||
</project> | </project> |
<option name="distributionType" value="DEFAULT_WRAPPED" /> | <option name="distributionType" value="DEFAULT_WRAPPED" /> | ||||
<option name="externalProjectPath" value="$PROJECT_DIR$" /> | <option name="externalProjectPath" value="$PROJECT_DIR$" /> | ||||
<option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-5.1.1" /> | <option name="gradleHome" value="$APPLICATION_HOME_DIR$/gradle/gradle-5.1.1" /> | ||||
<option name="gradleJvm" value="1.8 (2)" /> | |||||
<option name="modules"> | <option name="modules"> | ||||
<set> | <set> | ||||
<option value="$PROJECT_DIR$" /> | <option value="$PROJECT_DIR$" /> | ||||
</set> | </set> | ||||
</option> | </option> | ||||
<option name="resolveModulePerSourceSet" value="false" /> | <option name="resolveModulePerSourceSet" value="false" /> | ||||
<option name="useQualifiedModuleNames" value="true" /> | |||||
</GradleProjectSettings> | </GradleProjectSettings> | ||||
</option> | </option> | ||||
</component> | </component> |
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" /> | <configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" /> | ||||
</configurations> | </configurations> | ||||
</component> | </component> | ||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" project-jdk-name="1.8" project-jdk-type="JavaSDK"> | |||||
<output url="file://$PROJECT_DIR$/build/classes" /> | <output url="file://$PROJECT_DIR$/build/classes" /> | ||||
</component> | </component> | ||||
<component name="ProjectType"> | <component name="ProjectType"> |
byte[] mcuEncrypt(int cid, String mac, byte[] payload); | byte[] mcuEncrypt(int cid, String mac, byte[] payload); | ||||
/** | |||||
Broadcast data decryption method | |||||
*/ | |||||
byte[] decryptBroadcast(int cid, int vid,int pid, byte[] payload); | |||||
``` | ``` | ||||
### 5、How to use | ### 5、How to use |
byte[] mcuEncrypt(int cid, String mac, byte[] payload); | byte[] mcuEncrypt(int cid, String mac, byte[] payload); | ||||
/** | |||||
A7数据加密方法,cid为产品ID,ble协议中会包含 | |||||
*/ | |||||
byte[] mcuEncrypt(int cid, String mac, byte[] payload); | |||||
/** | |||||
广播数据解密方法 | |||||
*/ | |||||
byte[] decryptBroadcast(int cid, int vid,int pid, byte[] payload); | |||||
``` | ``` | ||||
### 五、使用方法 | ### 五、使用方法 |
androidTestImplementation 'androidx.test.ext:junit:1.1.2' | androidTestImplementation 'androidx.test.ext:junit:1.1.2' | ||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' | ||||
implementation 'com.github.elinkthings:AILinkSecretAndroid:1.0.0' | |||||
implementation 'com.github.elinkthings:AILinkSecretAndroid:2.0.0' | |||||
} | } |
} | } | ||||
/** | |||||
* 将广播数据进行解密 | |||||
* | |||||
* @param cid cid | |||||
* @param vid vid | |||||
* @param pid pid | |||||
* @param payload byte[] | |||||
* @return byte[] | |||||
*/ | |||||
public byte[] decryptBroadcast(int cid, int vid,int pid, byte[] payload) { | |||||
byte[] data = null; | |||||
if (payload != null && payload.length >= 1) { | |||||
data = AiLinkBleCheckUtil.decryptBroadcast(cid, vid, pid,payload); | |||||
} | |||||
return data; | |||||
} | |||||
public void close() { | public void close() { | ||||
if (mBluetoothGatt != null) { | if (mBluetoothGatt != null) { | ||||
mBluetoothGatt.disconnect(); | mBluetoothGatt.disconnect(); |
super.onScanResult(callbackType, result); | super.onScanResult(callbackType, result); | ||||
String address = result.getDevice().getAddress(); | String address = result.getDevice().getAddress(); | ||||
saveScanData(address); | saveScanData(address); | ||||
// SparseArray<byte[]> manufacturerSpecificData = result.getScanRecord().getManufacturerSpecificData();//获取自定义厂商数据列表,正常情况只有1个 | |||||
// if (manufacturerSpecificData.size() > 0) { | |||||
// byte[] data = manufacturerSpecificData.get(0); | |||||
// decryptBroadcastExample(data); | |||||
// } | |||||
} | } | ||||
} | } | ||||
} | } | ||||
/** | |||||
* 解密广播数据参考例子 | |||||
* @param data 自定义厂商数据 | |||||
*/ | |||||
private void decryptBroadcastExample(byte[] data){ | |||||
if (data.length < 3) | |||||
return; | |||||
byte[] cidB = new byte[1]; | |||||
byte[] vidB = new byte[1]; | |||||
byte[] pidB = new byte[1]; | |||||
int start = 0; | |||||
System.arraycopy(data, start, cidB, 0, cidB.length); | |||||
start += 1; | |||||
System.arraycopy(data, start, vidB, 0, vidB.length); | |||||
start += 1; | |||||
System.arraycopy(data, start, pidB, 0, pidB.length); | |||||
start += 1; | |||||
//特殊广播,包含是否可以绑定的标志 | |||||
int cid = (cidB[0] & 0xff); | |||||
int vid = (vidB[0] & 0xff); | |||||
int pid = (pidB[0] & 0xff); | |||||
byte[] decryptData=new byte[10];//根据协议取出需要解密的广播数据 | |||||
mAnalyticalDataUtil.decryptBroadcast(cid, vid, pid, decryptData); | |||||
} | |||||
/** | /** | ||||
* 搜索到的数据到列表 | * 搜索到的数据到列表 | ||||
*/ | */ |