Hello every1,
I am now working on a program for Android which is someting 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. In order to generate nonce, I tried using the code from this site.
http://www.exampledepot.com/egs/java.security/CreateSecureRandom.html
Part of my codes is as follow
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 begining.
But the problem is instead of getting a nonce value, it print as null at the client side. When I tried to print it on the server side, it also appear as null.
Can someone enlighten me the error in my codes or help me with a better or more suitable coding, please. Thanks a lot in advance.
Regards, Sebby.