I'm using an react native app to communicate with my miband 3, and part of its authentication process is encrypt a array of bytes using AES/ECB/NoPadding algorithm. I'm currently using this code as reference
Since I'm new to iot and encryption, I suppose that the lest step of its authentication is incorrect because and after writing to the miband 3 the encrypted byte array, I'm not getting authenticated properly.
Currently the last step looks like this:
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)
Notification is filtered because the first 3 bytes are used to tell which notification is happening, so I do not need them.
I must send the following to the miband 3 in order to authenticate properly:
const byteArrayToSend = [0x03,0x00, ...encryptedByteArray]
encryptedByteArray being my random number returned from miband notification (without the first 3 bytes) and properly encrypted .
I'm using 'crypto-js' and 'react-native-ble-manager' in the code.
How do I properly encrypt this bytearray using AES algorithm in order to send it?