@Test public void testRandomKey() throws Exception { int[] keySizes = {128, 192, 256}; for (int keySize : keySizes) { String key = TestUtils.getRandomKey(keySize); Properties props = getKMSProperties(key, keySize); VerifiableProperties verifiableProperties = new VerifiableProperties((props)); KeyManagementService<SecretKeySpec> kms = new SingleKeyManagementServiceFactory(verifiableProperties, CLUSTER_NAME, REGISTRY).getKeyManagementService(); SecretKeySpec randomKey = kms.getRandomKey(); Assert.assertNotNull("Random key cannot be null", randomKey); Assert.assertEquals("Key size mismatch", keySize, randomKey.getEncoded().length * 8); } }
@Override public SecretKeySpec getRandomKey() throws GeneralSecurityException { SecretKey secretKey = keyGen.generateKey(); byte[] encoded = secretKey.getEncoded(); return new SecretKeySpec(encoded, keyGenAlgo); }
SingleKeyManagementService implements KeyManagementService<SecretKeySpec> { @Override public SecretKeySpec getRandomKey() throws GeneralSecurityException { SecretKey secretKey = keyGen.generateKey(); byte[] encoded = secretKey.getEncoded(); return new SecretKeySpec(encoded, keyGenAlgo); } }
SingleKeyManagementService implements KeyManagementService<SecretKeySpec> { @Override public SecretKeySpec getRandomKey() throws GeneralSecurityException { SecretKey secretKey = keyGen.generateKey(); byte[] encoded = secretKey.getEncoded(); return new SecretKeySpec(encoded, keyGenAlgo); } SingleKeyManagementService(KMSConfig config, String defaultContainerKey); }
SingleKeyManagementService implements KeyManagementService<SecretKeySpec> { @Override public SecretKeySpec getRandomKey() throws GeneralSecurityException { SecretKey secretKey = keyGen.generateKey(); byte[] encoded = secretKey.getEncoded(); return new SecretKeySpec(encoded, keyGenAlgo); } SingleKeyManagementService(KMSConfig config, String defaultContainerKey); @Override void register(short accountId, short containerId); @Override void register(String context); @Override SecretKeySpec getKey(short accountId, short containerId); @Override SecretKeySpec getKey(String context); @Override SecretKeySpec getRandomKey(); @Override void close(); }
SingleKeyManagementService implements KeyManagementService<SecretKeySpec> { @Override public SecretKeySpec getRandomKey() throws GeneralSecurityException { SecretKey secretKey = keyGen.generateKey(); byte[] encoded = secretKey.getEncoded(); return new SecretKeySpec(encoded, keyGenAlgo); } SingleKeyManagementService(KMSConfig config, String defaultContainerKey); @Override void register(short accountId, short containerId); @Override void register(String context); @Override SecretKeySpec getKey(short accountId, short containerId); @Override SecretKeySpec getKey(String context); @Override SecretKeySpec getRandomKey(); @Override void close();  }