我正在使用 React Native 应用程序与我的 miband 3 进行通信,其身份验证过程的一部分是使用 AES/ECB/NoPadding 算法加密字节数组。我目前正在使用此代码作为参考
由于我是物联网和加密领域的新手,我认为其身份验证的最后一步是不正确的,因为在将加密字节数组写入 miband 3 后,我没有得到正确的身份验证。
目前最后一步看起来像这样:
const base_key = [0x01,0x23,0x45,0x67,0x89,0x01,0x22,0x23,0x34,0x45,0x56,0x67,0x78,0x89,0x90,0x02]
console.warn('Getting random number...')
const random_number = bytesToString(notification.filter((byte, index) => index > 3))
// Encrypting the key
const key = bytesToString(base_key)
const cipher = CryptoJS.AES.encrypt(random_number,key).toString()
// Step 5) Sending encrypted random number
console.warn('sending encrypted random number...')
const request_send_encrypted_key = [0x03,0x00, ...stringToBytes(cipher)]
await BleManager.writeWithoutResponse(miband3, service_uuid, characteristic_uuid, request_send_encrypted_key)
Run Code Online (Sandbox Code Playgroud)
通知被过滤,因为前 3 个字节用于告知正在发生哪个通知,所以我不需要它们。
我必须将以下内容发送到 miband 3 才能正确进行身份验证:
const byteArrayToSend = [0x03,0x00, ...encryptedByteArray]
Run Code Online (Sandbox Code Playgroud)
cryptoByteArray是我从 …