How to create NONCE and print it on the client side in ANDROID

Now I am working on an Android program that is related to IMS. I want the server to send nonce back to the client as a string and print it on the client side. To generate nonce , I tried using the code from this site.

http://www.exampledepot.com/egs/java.security/CreateSecureRandom.html

Some of my codes are as follows

public static String generateNonce() { 
  try {
   // Create a secure random number generator
   SecureRandom sr = SecureRandom.getInstance("SHA1PRNG");

   // Get 1024 random bits
   byte[] bytes = new byte[1024/8];
   sr.nextBytes(bytes);

   // Create two secure number generators with the same seed
   int seedByteCount = 10;
   byte[] seed = sr.generateSeed(seedByteCount);

   sr = SecureRandom.getInstance("SHA1PRNG");
   sr.setSeed(seed);
   SecureRandom sr2 = SecureRandom.getInstance("SHA1PRNG");
   sr2.setSeed(seed);
   } catch (NoSuchAlgorithmException e) {
  }
  //return NONCE;
  return null;
 }

I announced NONCE = generateNonce();at the beginning. But the problem is not to get the nonce value, it prints as null on the client side. When I tried to print it on the server side, it also looks like null .

- , . .

, Sebby.

+3
2

return , , (, , ) NONCE, null, String NONCE null.

return null. , NONCE , null.

+6

, , .

SecureRandom.

return null; .

, , :

 return sr.next(32);

, ​​ , .

+2

Source: https://habr.com/ru/post/1736247/


All Articles