use of org.apache.cayenne.crypto.key.KeySource in project cayenne by apache.
the class DefaultBytesTransformerFactoryTest method testCreateEncryptionHeader.
@Test
public void testCreateEncryptionHeader() {
Map<String, String> properties = new HashMap<>();
KeySource keySource = mock(KeySource.class);
when(keySource.getDefaultKeyAlias()).thenReturn("bla");
Header h1 = DefaultBytesTransformerFactory.createEncryptionHeader(properties, keySource);
assertNotNull(h1);
assertFalse(h1.isCompressed());
assertEquals("bla", h1.getKeyName());
properties.put(CryptoConstants.COMPRESSION, "false");
Header h2 = DefaultBytesTransformerFactory.createEncryptionHeader(properties, keySource);
assertFalse(h2.isCompressed());
assertEquals("bla", h2.getKeyName());
properties.put(CryptoConstants.COMPRESSION, "true");
Header h3 = DefaultBytesTransformerFactory.createEncryptionHeader(properties, keySource);
assertTrue(h3.isCompressed());
assertEquals("bla", h3.getKeyName());
}
use of org.apache.cayenne.crypto.key.KeySource in project cayenne by apache.
the class CryptoModuleBuilderTest method testBuild_KeySource.
@Test
public void testBuild_KeySource() {
URL ksUrl = JceksKeySourceTest.class.getResource(JceksKeySourceTest.KS1_JCEKS);
Module m = new CryptoModuleExtender().keyStore(ksUrl, JceksKeySourceTest.TEST_KEY_PASS, "k1").valueTransformer(DefaultValueTransformerFactory.class).module();
Injector injector = DIBootstrap.createInjector(new CryptoModule(), m);
KeySource ks = injector.getInstance(KeySource.class);
Key k1 = ks.getKey("k1");
assertNotNull(k1);
assertEquals("DES", k1.getAlgorithm());
String dkName = ks.getDefaultKeyAlias();
assertEquals("k1", dkName);
}
Aggregations