Categories
arrays dart string

Convert Uint8List to String with Dart

cipher.process returns an Uint8List which is a list of unsigned integers (0-255). I need to convert this Uint8List to a string that I can easily convert back to the same Uint8List.

    var cipherText = cipher.process( inputAsUint8List );        
return ASCII.decode(cipherText);

ASCII.decode throws an error since some of the integers are > 127.

I guess this should do it:

String s = new String.fromCharCodes(inputAsUint8List);
var outputAsUint8List = new Uint8List.fromList(s.codeUnits);