AuthKeyGen { public static AwsKeyPair generateKeypair() throws NoSuchAlgorithmException { String accessKey = "-"; String secretKey = "-"; while (accessKey.contains("-") || accessKey.contains("_") || secretKey.contains("-") || secretKey.contains("_")) { KeyGenerator generator = KeyGenerator.getInstance(AwsSignatureVersion2.HMAC_SHA_1); generator.init(120); byte[] awsAccessKeyId = generator.generateKey().getEncoded(); accessKey = BaseEncoding.base64Url().encode(awsAccessKeyId); generator.init(240); byte[] awsSecretAccessKey = generator.generateKey().getEncoded(); secretKey = BaseEncoding.base64Url().encode(awsSecretAccessKey); } return new AwsKeyPair(secretKey, accessKey); }  static AwsKeyPair generateKeypair();  }
@Test public void testNoMinusNoUnderscore() throws NoSuchAlgorithmException { for (int i = 0 ; i < 1000; i++){ AuthKeyGen.AwsKeyPair keyPair = AuthKeyGen.generateKeypair(); System.out.println(keyPair); assertFalse(keyPair.awsAccessKeyId.contains("-")); assertFalse(keyPair.awsAccessKeyId.contains("_")); assertFalse(keyPair.awsSecretAccessKey.contains("-")); assertFalse(keyPair.awsSecretAccessKey.contains("_")); } }