Method to generate AWS access keys
The recommended method to generate AWS Access Keys.
The generated AWS Access Keys provided to the system should be randomly generated alphanumeric strings of 20 and 40 characters. The secretAccessKey one should use a SecureRandom whereas the accessKeyId should use a normal Random.
The Access Key ID should be globally unique, since this will be used as the credential ID by the system
Code Sample
String accessKeyId = Util.randomAlphanumericString(20);
String secretAccessKey = Util.randomAlphanumericString(secureRandom, 40);
private static final char[] ALPHANUMERIC = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a',
'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
public static char randomAlphanumericCharacter(final Random random)
{
return ALPHANUMERIC[random.nextInt(ALPHANUMERIC.length)];
}
public static String randomAlphanumericString(final Random random, final int length)
{
final StringBuilder sb = new StringBuilder(length);
for (int i = 0; i < length; i++)
sb.append(randomAlphanumericCharacter(random));
return sb.toString();
}