1
I need to generate a 32byte code and encode for Base64, then Sha256 and Base64 again
But apparently this code has something wrong and I can’t understand what it is
var _random = Random.secure();
var random = List<int>.generate(32, (i) => _random.nextInt(256));
var verificador = base64Url.encode(random);
var base64ToSha256 = utf8.encode(verificador);
var desafio = base64Url.encode(base64ToSha256);
I tried that:
var uuid = Uuid();
var random = uuid.v4();
var verificador = base64Url.encode(random);
var base64ToSha256 = sha256.convert(verificador);
var desafio = base64Url.encode(base64ToSha256);
but apparently I’m very devoid of intelligence and I’m doing something very wrong...
Just one detail: Base64 nay is cryptography, is just one data coding algorithm. Another point is to do
sha256(base64(string))
will not bring much more advantages than simply doingsha256(string)
: any crazy combination of those doesn’t make much difference in terms of security...– hkotsubo
@hkotsubo thanks for the information but I really need to do so, I am not inventing my own cryptography, I’m just doing things like you asked me to do
– AristoEinstein
Actually I put the link because there are other links explaining that it makes no difference to make this combination of Base64 with Base64 hash again. Anyway, it would be interesting to explain to those who asked that it makes no difference this first conversion to Base64 before calculating the hash (then it may make sense depending on how you transmit the data, although for hashes it is more common to represent the bytes as hexadecimal digits, but finally...)
– hkotsubo
@hkotsubo
codigo_desafio
: [Generate a random 32 bytes, convert to hexadecimal, encode with Base64, replace the "+" and "/" characters with "-" and "_" respectively, and remove the "=" characters to get the codeverificador
(will be used in the next step), with this SHA256 encryption code and code with Base64 securely to URL (as you did earlier by removing the characters)]– AristoEinstein
@Aristoeinstein Why do you think you have something wrong with your code? Does it return any errors? Its first code, ran it and ran without returning errors.
– Matheus Ribeiro
@Matheusribeiro the first code was wrong sorry This is the error it returns:
The argument type 'String' can't be assigned to the parameter type 'List<int>'
– AristoEinstein