I have a sha256 hash which is
5d753fd209b8cb9dff6801edbc60f2fdc00abff56bf3ef8c0f7cf9b975a2a1f9
and i know what i should get at the end which is this base64 encoded String
N7m2mKF7vY8tM8PVvkPONqnu5gdXWPm+vcT3lkpBWZ8=
but can’t figure out how to get this.
Just now i have tryed this
var hexString = '5d753fd209b8cb9dff6801edbc60f2fdc00abff56bf3ef8c0f7cf9b975a2a1f9';
var hexArray = HexUtils.decode(hexString);
var base64String = base64Encode(hexArray);
print('base64String: $base64String');
which print’s to the console
XXU/0gm4y53/aAHtvGDy/cAKv/Vr8++MD3z5uXWiofk=
what is not what i want. It should give me
N7m2mKF7vY8tM8PVvkPONqnu5gdXWPm+vcT3lkpBWZ8=
Any help is very much appreciated. Thank you so much.
I use the package basic_utils for HexUtils.decode and dart:convert for base64Encode
2
Answers
I think you should use
<string>.codeUnits
property to get theList<int>
and use it for base64encode.Example
Output :
However, this is not 100% the same as you required. Tried using https://www.base64encode.org/, and encoded your hex string, the output is same as mine and not yours.
It looks like you’re on the right track, but there might be a small issue with how the hex string is being decoded. Let’s try a different approach to ensure the hex string is correctly converted to bytes before encoding it to base64.
Here’s a complete example using Dart:
This should give you the correct base64 encoded string. Let me know if this works for you!