Search in sources :

Example 1 with KeySource

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());
}
Also used : KeySource(org.apache.cayenne.crypto.key.KeySource) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 2 with KeySource

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);
}
Also used : KeySource(org.apache.cayenne.crypto.key.KeySource) Injector(org.apache.cayenne.di.Injector) DefaultValueTransformerFactory(org.apache.cayenne.crypto.transformer.value.DefaultValueTransformerFactory) Module(org.apache.cayenne.di.Module) URL(java.net.URL) Key(java.security.Key) JceksKeySourceTest(org.apache.cayenne.crypto.key.JceksKeySourceTest) Test(org.junit.Test)

Aggregations

KeySource (org.apache.cayenne.crypto.key.KeySource)2 Test (org.junit.Test)2 URL (java.net.URL)1 Key (java.security.Key)1 HashMap (java.util.HashMap)1 JceksKeySourceTest (org.apache.cayenne.crypto.key.JceksKeySourceTest)1 DefaultValueTransformerFactory (org.apache.cayenne.crypto.transformer.value.DefaultValueTransformerFactory)1 Injector (org.apache.cayenne.di.Injector)1 Module (org.apache.cayenne.di.Module)1