@Test public void testKeyInfoGenerationProfile() throws ResolverException { roleDesc .getKeyDescriptors() .add(buildKeyDescriptor(rsaCred1KeyName, UsageType.ENCRYPTION, rsaCred1.getPublicKey())); resolver.setAutoGenerateDataEncryptionCredential(true); criteriaSet.add(new KeyInfoGenerationProfileCriterion("testKeyInfoProfile")); defaultDataEncryptionKeyInfoGeneratorManager.setUseDefaultManager(true); defaultKeyTransportKeyInfoGeneratorManager.setUseDefaultManager(true); EncryptionParameters params = resolver.resolveSingle(criteriaSet); Assert.assertNotNull(params.getDataKeyInfoGenerator()); Assert.assertNotNull(params.getKeyTransportKeyInfoGenerator()); defaultDataEncryptionKeyInfoGeneratorManager.setUseDefaultManager(false); defaultKeyTransportKeyInfoGeneratorManager.setUseDefaultManager(false); params = resolver.resolveSingle(criteriaSet); Assert.assertNull(params.getDataKeyInfoGenerator()); Assert.assertNull(params.getKeyTransportKeyInfoGenerator()); defaultDataEncryptionKeyInfoGeneratorManager.setUseDefaultManager(false); defaultKeyTransportKeyInfoGeneratorManager.setUseDefaultManager(false); defaultDataEncryptionKeyInfoGeneratorManager.registerFactory( "testKeyInfoProfile", new BasicKeyInfoGeneratorFactory()); defaultKeyTransportKeyInfoGeneratorManager.registerFactory( "testKeyInfoProfile", new BasicKeyInfoGeneratorFactory()); params = resolver.resolveSingle(criteriaSet); Assert.assertNotNull(params.getDataKeyInfoGenerator()); Assert.assertNotNull(params.getKeyTransportKeyInfoGenerator()); }
@Test public void testGeneratedDataCredential() throws ResolverException { roleDesc .getKeyDescriptors() .add(buildKeyDescriptor(rsaCred1KeyName, UsageType.ENCRYPTION, rsaCred1.getPublicKey())); resolver.setAutoGenerateDataEncryptionCredential(true); EncryptionParameters params = resolver.resolveSingle(criteriaSet); Assert.assertNotNull(params); Assert.assertEquals( params.getKeyTransportEncryptionCredential().getPublicKey(), rsaCred1.getPublicKey()); Assert.assertEquals(params.getKeyTransportEncryptionAlgorithm(), defaultRSAKeyTransportAlgo); Assert.assertNotNull(params.getKeyTransportKeyInfoGenerator()); Assert.assertNotNull(params.getDataEncryptionCredential()); Assert.assertNotNull(params.getDataEncryptionCredential().getSecretKey()); Assert.assertEquals(params.getDataEncryptionAlgorithm(), defaultAES128DataAlgo); Assert.assertEquals( KeySupport.getKeyLength(params.getDataEncryptionCredential().getSecretKey()), new Integer(128)); Assert.assertNotNull(params.getDataKeyInfoGenerator()); }