How to generate such MD5 hash on MCU, if the API is already used, cannot be changed ?
For Android it was used the sub (with help of Encryption lib):
B4X:
'algorithm is often used "MD5"
Sub Get_Hash(Text As String, algorithm As String) As String
Dim bc As ByteConverter
Dim md As MessageDigest
Dim data() As Byte
Dim encrypted() As Byte
data = bc.StringToBytes(Text, "UTF-8")
encrypted = md.GetMessageDigest(data, algorithm)
Dim res As String = bc.HexFromBytes(encrypted)
Return (res)
End Sub
Sub Process_Globals
Public Serial1 As Serial
Private MD5Result(16) As Byte
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Dim b() As Byte = "abcd"
RunNative("CalcMD5", b)
For i = 0 To MD5Result.Length - 1
Log(MD5Result(i))
Next
Dim bc As ByteConverter
Log(bc.HexFromBytes(MD5Result))
End Sub
#if C
#include <MD5Builder.h>
MD5Builder md5;
void CalcMD5(B4R::Object* o) {
B4R::Array* b = (B4R::Array*)B4R::Object::toPointer(o);
md5.begin();
md5.add((uint8_t *)b->data, b->length);
md5.calculate();
md5.getBytes((uint8_t *)b4r_main::_md5result->data);
}
#End If