SHA 256 for android app [复制]

This question already has an answer here:

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.

</div>

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();