1

I have the following PHP function which generates tokens. It uses md5 hashing algorithm and mcrypt_create_iv in the following manner.

public static function generate_token($length = 32) 
{
   $char_str = strtoupper(md5(mcrypt_create_iv($length, MCRYPT_DEV_URANDOM)));
   $token = substr($char_str, 0, $length);
   return $token;
}

I want to perform the same task in Java. But I am not sure which libraries to use.

Pattu
  • 3,481
  • 8
  • 32
  • 41
  • 1
    maybe this can help you: http://stackoverflow.com/questions/21264678/java-mcrypt-create-iv – swidmann Nov 13 '15 at 10:29
  • I see no reason why MD5 must be used here unless this is a lazy attempt at converting something to hex. – Artjom B. Nov 13 '15 at 10:30
  • @swidmann I followed the link. But it's different. It doesn't even use md5 or read /dev/urandom file. – Pattu Nov 13 '15 at 10:33
  • @Pattu the example doesn't need `/dev/urandom` it has `SecureRandom()` and by the way you are using `md5()` on your script, so you can also use your own md5 function in Java – swidmann Nov 13 '15 at 10:36
  • What about this [one](http://stackoverflow.com/questions/17721982/require-similler-java-code-for-php-encryption-script) – Maraboc Nov 13 '15 at 10:41
  • @Maraboc It looks good. I will give it a try. – Pattu Nov 13 '15 at 10:49

0 Answers0