Passing generated byte key to mobile app

Hey guys,

I am very new to Arduino project and trying my hands on building my first temperature humidity sensor. I am using a NodeMCU ESP8266 as the microcontroller board. I connected a HC-05 for bluetooth functionality. I wanted to do encryption on data being passed between the device and my mobile app (build using react native). I am using the arduino crypto library. I wanted to use the shared key I wanted to pass the WiFi credentials to the device encrypted using the key. I used the below code to generate the key and pass it to the mobile app.

void getConnected() {
  // wait till someone try to connect to the user
  if (btSerial.available() > 0) {
    String message =  btSerial.readString();
    if(message == "Hello") {
      Serial.println("user trying to connect");
      byte key[32];
      device.getKey(key);
      Serial.println((char *)key);
      btSerial.write((char *)key);
    }
    
  }
}

the device.getKey(key) is as follows:

void Device::getKey(byte* key) {
	RNG.rand(key, sizeof(key));
}

The issue I am facing is that the RNG generates the key as a array of byte. I printed the bytes and it was something like this:

137 224 186 115 0 0 0 0 172 228 254 63 131 53 32 64 208 218 255 63 13 0 0 0 172 228 254 63 48 70 32 64 0

When the data is received in the mobile app, it is returning only the first 4 bytes because it is encountering a 0 after that and stopping the transmission. I am not really sure the best way to get this across to the mobile app. I tried converting every byte to String object and concatenating it but that didn't work either. Its returning something like

89e0ba730000ace4fe3f83352040d0daff3fd000ace4fe3f304620400

And I am not sure how to convert the same back into the byte array in React Native.

I apologize if this is a repeated question. I would really appreciate some help here. I am stuck with getting the cryptography to work between the React Native app and ESP8266 for the last 2 days.

Thanks in advance for any pointers.

What data format does the mobile app expect to receive? Why would it stop on a zero?

Thanks for your quick response. I am expecting a UTF8 format. I am not very sure why it stops, but my guess is that 0 is treated as a end-of-string character. I am using the react-native-bluetooth-serial library to read the data from the device. The code looks as below:

  async setup(deviceId) {
    console.log('connecting');
    await BluetoothSerial.connect(deviceId);
    console.log('connected');
    await BluetoothSerial.write('Hello');
    setTimeout(async () => {
      let key = await BluetoothSerial.readFromDevice();
      console.log(key);
    }, 3000);
    // const input = await BluetoothSerial.readFromDevice();
    return true;
  }

anyone working on cryptography with arduino and mobile app? Please help