0

I have in PHP this method to call a security web service:

// token generator; date is UTC/GMT
$tokenNewInputData = date("Y-m-d");
$tokenNew = hash_hmac('sha256', $tokenNewInputData, KEY);
echo ‘token: ‘.$tokenNew;

where KEY it's "password" text.

I must use the same method into Android app for generate a security code in the same way and add this to a string for get call.

Can you help me please for an example to traslate this PHP code into Android code? Thanks.

Unheilig
  • 16,196
  • 193
  • 68
  • 98
DEV
  • 31
  • 1
  • 7
  • Is it the same as this: http://stackoverflow.com/questions/1609899/java-equivalent-to-phps-hmac-sha1 ? – Rickard Apr 25 '15 at 11:24

1 Answers1

0

write down below code.

MessageDigest md = MessageDigest.getInstance("SHA-256");
String text = "This is some text";
md.update(text.getBytes("UTF-8")); // Change this to "UTF-16" if needed
byte[] digest = md.digest();
Milap Pancholi
  • 134
  • 1
  • 12