As I navigate through the world of IoT and encryption, I find myself encountering a challenge with my React Native app that communicates with my MiBand 3. As part of the authentication process, I need to encrypt an array of bytes using the AES/ECB/NoPadding algorithm. To guide me, I have been referring to this code provided by Yogesh Ojha.
However, despite following the steps outlined in the reference code, I suspect that the final step of authentication might be incorrect. After transmitting the encrypted byte array to the MiBand 3, I am facing authentication issues.
The current implementation of the last step involves:
const base_key = [0x01,0x23,0x45,0x67,0x89,0x01,0x22,0x23,0x34,0x45,0x56,0x67,0x78,0x89,0x90,0x02]
console.warn('Obtaining 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) Transmitting encrypted random number
console.warn('Transmitting encrypted random number...')
const request_send_encrypted_key = [0x03,0x00, ...stringToBytes(cipher)]
await BleManager.writeWithoutResponse(miband3, service_uuid, characteristic_uuid, request_send_encrypted_key)
The notification data is filtered because the first 3 bytes indicate the type of notification, which are unnecessary for the encryption process.
To authenticate successfully, I must send the following to the MiBand 3:
const byteArrayToSend = [0x03,0x00, ...encryptedByteArray]
The encryptedByteArray should contain the properly encrypted random number retrieved from the MiBand notification (excluding the first 3 bytes).
In my code, I am utilizing 'crypto-js' library along with 'react-native-ble-manager'. However, I am struggling to implement the AES encryption correctly for sending the bytearray. Can anyone guide me on how to achieve this?