cryptography
cryptography copied to clipboard
How to convert a SecretKey to a string
toString returns "SecretKey(...)" instead of a String representation of its bytes. But I need a string representation in order to save this to secure storage using https://pub.dev/packages/flutter_secure_storage
Why doesn't toString handle this conversion for me? Can you recommend a workaround?
I will go with using "extract" I guess to get a List of ints, then then dart:convert to get the String that I need:
List
Ideally this should be baked into the "toString" override though, right?
@override
String toString() => base64Encode(_bytes);
List<int> fromString(String str) => base64Decode(str);
This works, not utf8. Recommend baking it into the SecretKey class!
any news?
In my case, to convert a string in a key i use:
String key ="this is my key";//
var hashAlgor = Sha512();// instance of object
var hash = await hashAlgor.hash(utf8.encode(key));// convert the key to get a hash of a key
var secretKey = SecretKeyData(hash.bytes);// get data of key
var secretBox =
await algorithm.encrypt(mensageInt, secretKey: secretKey); //pass secret key
Thank you for the issue report! I close the issue as I don't think such method will be added.