How do I write a byte array in Dart? I want to implement this function, but it is Java code with byte[]
in it. Can it be written in Dart as well?
public static byte[] encrypt(byte[] key, byte[] data) throws Exception {
try {
return performCipher(Cipher.ENCRYPT_MODE, key, data);
} catch (Exception e) {
throw new Exception(e);
}
}
The easiest approach would be to create a byte list ( Uint8list ), then view the underlying buffer as a 32-bit integer list ( Int32List ) and store the integer there. That will allow you to read back the bytes.
A byte array is simply a collection of bytes. The bytearray() method returns a bytearray object, which is an array of the specified bytes. The bytearray class is a mutable array of numbers ranging from 0 to 256.
json now lets you put a byte[] object directly into a json and it remains readable. you can even send the resulting object over a websocket and it will be readable on the other side.
What you are looking for is Uint8List
. It is the equivalent of byte[]
of Java in Dart. Every single value has an equivalent in another language, so byte[]
in a few languages is like:
byte[]
Uint8List
FlutterStandardTypedData -> typedDataWithBytes
I recommend looking at the documentation for more: https://flutter.dev/docs/development/platform-integration/platform-channels#codec
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With