Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I write byte array in Dart?

Tags:

java

flutter

dart

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);
    }
}
like image 961
Vimbiso Murungu Avatar asked Jul 31 '19 12:07

Vimbiso Murungu


People also ask

How do you convert int to byte in darts?

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.

What is byte type array?

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.

Can you store bytes in JSON?

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.


1 Answers

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:

  1. Java: byte[]
  2. Dart: Uint8List
  3. iOS: FlutterStandardTypedData -> typedDataWithBytes

I recommend looking at the documentation for more: https://flutter.dev/docs/development/platform-integration/platform-channels#codec

like image 111
Gaurav Mall Avatar answered Oct 21 '22 14:10

Gaurav Mall