They both return same results with mysql one in lowercase while b4a one in uppercase. I was hoping that B4A returns an identical result as mysql. What did I do incorrectly?
TIA
Test message: "The quick brown fox jumps over the lazy dog"
MySQL version: 10.2.43-MariaDB
mysql code:
SELECT length(SHA2('The quick brown fox jumps over the lazy dog', 256))
, SHA2('The quick brown fox jumps over the lazy dog', 256)
/* output: 64, d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592
*/
b4a code:
Public Sub Sha256(msg As String) As String
Dim md As MessageDigest
Dim msgBytes() As Byte= md.GetMessageDigest(msg.GetBytes("UTF8"),"SHA-256")
Dim strResult As String=bc.HexFromBytes(msgBytes)
Log(strResult.Length & ": " & strResult) 'output: 64: D7A8FBB307D7809469CA9ABCB0082E4F8D5651E46D3CDB762D02D0BF37C9E592
Return strResult
End Sub
why not hope that mysql would return the same result as b4a?
the standard uses upper case. you chose to convert bytes to a string for the comparison; you need to compare bytes. or, now that you know all vendors don't handle the conversion to string the same way, be prepared to change one of the results to upper/lower case, as needed.