Using DisgestUils.md5Hex to generate 32 digits random number in java. It's being captured as Violation in veracode report.
Could you please advise how do I generate 32 digits number in java which should not capture in veracode report.
Using DisgestUils.md5Hex to generate 32 digits random number in java. It's being captured as Violation in veracode report.
Could you please advise how do I generate 32 digits number in java which should not capture in veracode report.
While I can't speak for Veracode, you probably want to use an instance of SecureRandom to create random numbers for cryptographic or security token purposes.
To get thirty two hexadecimal characters out of SecureRandom you need sixteen bytes and can then use a StringBuilder to turn those bytes into a String cheaply.
For example:
import java.security.SecureRandom;
...
SecureRandom random = new SecureRandom();
byte[] bytes = new byte[16];
random.nextBytes(bytes);
StringBuilder builder = new StringBuilder();
for (byte b : bytes) {
String hex = Integer.toHexString(b & 0xff);
if (hex.length() == 1) {
builder.append('0');
}
builder.append(hex);
}
String token = builder.toString();