Hello all ,
I am trying to convert the following Java to B4A but have no luck in converting string.format("%032x", new BigInteger(1, md.digest()));
Can you please help ?
I used a snippet from forums but I think I am not implementing it correctly.
Thanks in advance
I am trying to convert the following Java to B4A but have no luck in converting string.format("%032x", new BigInteger(1, md.digest()));
Can you please help ?
B4X:
MessageDigest md = MessageDigest.getInstance("MD5");
long timeInSeconds = (System.currentTimeMillis() / 1000);
String input = apikey + secret + timeInSeconds;
md.update(input.getBytes());
String sig = String.format("%032x", new BigInteger(1, md.digest()));
String url = service + version + method + "?apikey=" + apikey
+ "&sig=" + sig + otherElementsStr + "hotelIdList=" + hotelId;
B4X:
Sub hashing
Dim md As MessageDigest
Dim input As String="my api key"&"secret"&(DateTime.Now/1000)
Dim bint As JavaObject
bint.InitializeNewInstance("java.math.BigInteger",Array(1,md.GetMessageDigest(input.GetBytes("UTF8"),"MD5")))
Log(bint)
FormatString(bint,"%032x")
End Sub
Sub FormatString(str As String,strformat As String) As String
'Create a Stringbuilder (it's much faster for appending strings)
Log("STR: "&str)
Dim SB As StringBuilder
SB.Initialize
'Create the Formatter Object
Dim Format As JavaObject
Format.InitializeStatic("java.lang.String")
'Create an array of arrays that holds our data.
'We could have been read from a CSV file using StringUtils and converted to an array of arrays using Regex.Split
'NOTE: the array must be of type Object
Dim Data(1) As Object
Data(0) = Array As Object(str)
' Data(1) = Array As Object("Peter","2","Home","\n")
' Data(2) = Array As Object("Michael","3","Away","\n")
' Data(3) = Array As Object("Ann","4","Home","\n")
Log("0: "&Data(0))
Dim FormatStr As String = strformat
For Each Line() As Object In Data
Log(Line)
SB.Append(Format.RunMethod("format",Array As Object(FormatStr,Line)))
Next
Return SB.ToString
End Sub
I used a snippet from forums but I think I am not implementing it correctly.
Thanks in advance