I am now working on a program for Android which is something related to IMS. I want the server to send back a nonce to the client as a string and print it on the client-side.
Part of my code, from Generating a Secure Random Number:
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 declared NONCE = generateNonce();
in the beginning.
But the problem is instead of getting a nonce value, it prints null on the client-side. When I tried to print it on the server-side, it also appears to be null.
Can someone enlighten me on the error in my code or help me with better or more suitable coding?