首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法验证Mi Band2

无法验证Mi Band2
EN

Stack Overflow用户
提问于 2018-04-24 14:27:01
回答 1查看 606关注 0票数 0

我试图将应用程序与Mi Band2连接并进行身份验证,但在最后一步(发送加密密钥并接收成功的身份验证响应)上,我会收到错误响应。第一步、第二步和第三步是成功的,没有例外。这是所有认证代码。

  1. 具有认证级别1的主Auth方法(通知需要触摸响应的频带)
  2. 检查authCharacteristic的新更新并等待来自频带的新响应。有句柄2、3和4级别的身份验证。
  3. 加密到AES/ECB/NoPadding加密(我也尝试过AesCbc,但结果相同)。 公共异步任务身份验证(){ var authCharacteristic =等待Gatt.GetCharacteristicByServiceUuid(新Guid("0000FEE1-0000-1000-8000-00805F9B34FB"),新的authCharacteristic //订阅通知等待authCharacteristic.WriteClientCharacteristicConfigurationDescriptorAsync(GattClientCharacteristicConfigurationDescriptorValue.Notify);//级别1 Debug.WriteLine(“级别1已启动”);authCharacteristic.WriteValueAsync(sendKey.ToArray().AsBuffer()) secretKey =新的byte[] { 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x40,0x41,0x42,0x43,0x44,0x45 };List sendKey =新列表();sendKey.Add(1);sendKey.Add(8);sendKey.AddRange(secretKey);if (等待== GattCommunicationStatus.Success) {Debug.WriteLine(“一级成功”);返回authCharacteristic_ValueChanged(GattCharacteristic发送方( GattValueChangedEventArgs args) { var authCharacteristic = authCharacteristic.ValueChanged Gatt.GetCharacteristicByServiceUuid(新Guid(“0000FEE1-0000-1000-800-00805F9B34FB”),新Guid)if (sender.Uuid.ToString() == "00000009-0000-3512-2118-0009af100700") {Debug.WriteLine(“接收特征值:”+ args.CharacteristicValue.ToArray().ToList());Debug.WriteLine(“接收到的SendKey:”+args.CharacteristicValue.ToArray Debug.WriteLine(“接收状态:”+ args.CharacteristicValue.ToArray().ToList()2);))变量请求= args.CharacteristicValue.ToArray().ToList();字节authResponse = 0x10;字节authSendKey = 0x01;字节authRequestRandomAuthNumber = 0x02;字节authRequestEncryptedKey = 0x03;字节authSuccess = 0x01;字节authFail = 0x04;List authNumber =新List();authNumber.Add(0x02);authNumber.Add(0x08);if (等待authNumber.Add == GattCommunicationStatus.Success) Debug.WriteLine(“二级成功”);}否则if (request == authResponse & request1 == authRequestRandomAuthNumber & request2 == authSuccess) {Debug.WriteLine(“3级开始”);List randomKey =新List();List relevantResponsePart =新List();var responseValue = args.CharacteristicValue.ToArray();for (int i= 0;i< responseValue.Count();{ if (i randomKey.AddRange(Encrypt(relevantResponsePart.ToArray()));3) relevantResponsePart.Add(responseValuei);} randomKey.Add(0x03);randomKey.Add(0x08);relevantResponsePart.Add(ResponseValuei)如果(等待authCharacteristic.WriteValueAsync(randomKey.ToArray().AsBuffer()) == GattCommunicationStatus.Success) Debug.WriteLine(“3级成功”);}否则if (request == authResponse & request1 == authRequestEncryptedKey & request2 == authSuccess) { //无法到达此代码。最后一个字节是4(错误)。Debug.WriteLine(“已完成”);isAuthed =真;}}公共byte[]加密( byte[]数据){ byte[] secretKey =新byte[]{ 0x30、0x31、0x32、0x33、0x34、0x35、0x36、0x37、0x38、0x39、0x40、0x41、0x42、0x43、0x44、0x45 };string aesKey = Convert.ToBase64String(secretKey);IBuffer key = Convert.FromBase64String(aesKey).AsBuffer();SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcb);algorithmProvider = algorithmProvider.CreateSymmetricKey(key);IBuffer buffEncrypt = CryptographicEngine.Encrypt( ckey,data.AsBuffer(),null);返回buffEncrypt.ToArray();}

这里控制台中的所有调试消息:

代码语言:javascript
复制
Connected to MI Band 2
Level 1 started
Level 1 success
Received characteristic value: 16
Received SendKey: 1
Received Status: 1
Level 2 started
Level 2 success
Received characteristic value: 16
Received SendKey: 2
Received Status: 1
Level 3 started
Level 3 success
Received characteristic value: 16
Received SendKey: 3
Received Status: 4
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-25 15:12:17

当我在加密()中更改字符串时,问题得到了解决

代码语言:javascript
复制
byte[] secretKey = new byte[] { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45 };
IBuffer key = secretKey.AsBuffer();

我想我的问题是密码不对。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50004193

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档