`byte[] bytes = System.Text.Encoding.GetEncoding("ISO-8859-9").GetBytes(str);
byte[] hashingbytes = sha.ComputeHash(bytes);
String hash = Convert.ToBase64String(hashingbytes);`
this is a c# code When I try to hash similarly in flutter, the data is not the same. How can I do this in Flutter
Related
Basically I'm trying to convert a base64 jpeg image to normal image in flutter using
Image.memory(base64Decode(stringBase64))
the image initially used to be jp/2 format which isn't supported by flutter so i converted the jp/2 base64 string to bitmap in java and then to base64 string jpeg to be able to decode it in flutter using this code :
public static String encodeToBase64(Bitmap image)
{
Bitmap immagex=image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
immagex.compress(Bitmap.CompressFormat.JPEG, 100, baos);
byte[] b = baos.toByteArray();
String imageEncoded = Base64.encodeToString(b, Base64.DEFAULT);
return imageEncoded;
}
how ever when i try to decode this base64 string in flutter i'm getting this error
Invalid character (at character 77)
/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAIQAABtbnRyUkdC
which is pointing to the last C in the given line.
i don't seem understand where does the issue come from since i can convert my base64 string to image online but in flutter it throws that exception every time
thank you very much #Jamesdlin for the solution that was given in the comments
The issue was due to whitespace in the base64 string , solved by using
base64.decode(photoBase64.replaceAll(RegExp(r'\s'), '')),
If your URI contains data after the comma as it is defined by RFC-2397. Dart's Uri class is based on RFC-3986, so you can't use it.
Split the string by a comma and take the last part of it:
String uri = 'data:image/gif;base64,...';
Uint8List _bytes = base64.decode(uri.split(',').last);
REFERENCE: https://stackoverflow.com/a/59015116/12382178
I have a compress function like below, which has a return value List<int>
List<int> compressData() {
var stringBytes = utf8.encode(plainText);
return BZip2Encoder().encode(stringBytes);
}
then I want to encrypt the data with salsa20 from the package encrypt, but must be string data as input data, I've tried with toString() but it makes the data 2X bigger, how to solve the problem?
So this is my code
_image1 = File(pickedImage.path);
List<int> imageBytes = _image1.readAsBytesSync();
String base64Image = base64.encode(imageBytes);
_shcpImg = base64Image;
But when I print the string _shcpImg, it just prints a part of the string, because when I copy and paste that base64 into an online converter, it only shows a really tiny piece of the image. So the thing is that the string is not showing completely or somehow the base64 encoder is not working well.
Any suggestions?
From the comments, since you are using VsCode and you can't print the full string (long string)
You can use log from dart: developer,
if the string is REALLY LONG, There is a workaround to fix this, the idea is to divide your long string into small pieces (in the example, 800 length for each piece) using RegExp and then iterate into the result and print each piece.
void printWrapped(String text) {
final pattern = new RegExp('.{1,800}'); // 800 is the size of each chunk
pattern.allMatches(text).forEach((match) => print(match.group(0)));
}
I am trying to convert a Uint8List to a string using Dart (in a Flutter project).
I am using the Flutter Android USB Serial plugin ( https://github.com/altera2015/usbserial)
The data are coming from a usb device and are returned from the library as a Stream.
If outputed as a string, it looks like:
[255,0,0,0,255....]
When I try:
String newTag = ascii.decode(asyncSnapshot.data);
I get the error :
FormatException:Invalid value in input: 255
I don't know how to solve this issue, my result should be :
"352206000079439"
Try this one;
List<int> list = 'someData'.codeUnits;
Uint8List bytes = Uint8List.fromList(list);
String string = String.fromCharCodes(bytes);
If data has compressed as a blob type.
Uint8List bytes = Uint8List.fromList(tcp_socket_blob_data);
var inflated = zlib.decode(bytes);
var data = utf8.decode(inflated);
More: flutter/dart: How to decompress/inflate zlib binary string in flutter
When trying to read a PDF417 barcode that contains embedded NULL characters:
// load image and convert to bitmap
Bitmap bmp = new Bitmap(Image.FromFile(#"C:\Sample.png"));
IBarcodeReader reader = new BarcodeReader();
ZXing.Result result = reader.Decode(bmp);
// do something with the result
String decodedString = result.Text;
The returned text is cut off when it encounters an embedded null character:
IDUS3*1GORRELL, LIDIA 9991001041 0060150RDBR1992OCT31NNYYUNONE NONE 2RRT 2011NOV042052OCT308 5RESRETUSAF AMN E1 I UNKÿØÿà
What i need is the RawBytes of the PDF417 barcode.
Other, hardware, decoders do return the entire string (since it is perfectly valid for a string to contain embedded NULL characters).
There is a:
Byte[] rawResult = result.RawBytes;
But RawBytes is always null - it doesn't mean what you think it means. It is not the RawBytes of the read barcode; it is the raw bytes from a QR code.
How can i get the raw bytes encoded on a PDF417 card?