Future<void> _showEncryptedImageDialog() async {
if (_selectedImage == null) {
// Handle case where no image is selected
print('No image selected');
return;
}
final Uint8List originalImageData = await _selectedImage!.readAsBytes();
final Uint8List encryptedImageData =
_imageEncryptor.encryptImage(originalImageData);
print(encryptedImageData);
var image = Image.memory(encryptedImageData);
if (encryptedImageData.isEmpty) {
print("No data to encrypt");
}
showDialog(
context: context,
builder: (BuildContext context) {
return Dialog(
child: Row(
children: [
// Image.memory(
// (originalImageData),
// ),
image,
ElevatedButton(
onPressed: () {
Navigator.pop(context);
},
child: const Text('Close'),
),
],
),
);
},
);
}
I am getting this error
Exception caught by image resource service
The following _Exception was thrown resolving an image codec:
Exception: Invalid image data
I want to display the encrypted image in my flutter app and but it is giving me this error and i tried doing the same for the original image data and it displayed but it is unable to display my encrypted. Ps: I am beginner in flutter so your solutions will help me a lot
Did you really mean ‘encrypted’ as in ‘convert (information or data) into a code, especially to prevent unauthorized access’?
No, I meant that i am encrypting the original image uploaded by the user from their gallery then i am gonna encrypt it using AES and then display the encrypted image
First off, the whole point of encryption is to not know what it actually is that means that it is impossible to show an encrypted image (without decrypting it first). But I don’t know why you want to encrypt the image in the first place, as it is already decrypted on the device.
You can’t use the encrypted bytes to display an image. That data is nonsense until it’s decrypted again.