@Test public void testEncryptKey() throws Exception { String testSecret = "my-test-val"; final String masterkey = AesKeyHelper.createRandomBase64Key(); SakuliPropertyPlaceholderConfigurer.ENCRYPTION_KEY_VALUE = masterkey; final Map.Entry<String, String> kv = CipherDelegator.encrypt(testSecret); assertEquals(kv.getKey(), "environment masterkey"); assertTrue(kv.getValue().length() > testSecret.length()); CipherProperties props = new CipherProperties(); props.setEncryptionKey(masterkey); assertEquals(new EnvironmentCipher(props).decrypt(kv.getValue()), testSecret); }
public static Map.Entry<String, String> encrypt(String strToEncrypt) throws SakuliCipherException { loadEnvironmentVariables(); Properties props = new Properties(); SakuliPropertyPlaceholderConfigurer.assignEncryptionProperties(props); CipherProperties cipherProps = CipherProperties.load(props); switch (cipherProps.getEncryptionMode()) { case CipherProperties.ENCRYPTION_MODE_ENVIRONMENT: return new AbstractMap.SimpleEntry<>("environment masterkey", new EnvironmentCipher(cipherProps).encrypt(strToEncrypt)); case CipherProperties.ENCRYPTION_MODE_INTERFACE: NetworkInterfaceCipher cipher = new NetworkInterfaceCipher(cipherProps); cipher.scanNetworkInterfaces(); return new AbstractMap.SimpleEntry<>("interface " + cipher.getInterfaceName(), cipher.encrypt(strToEncrypt)); default: throw new SakuliCipherException("unexpected error during encryption"); } }
CipherDelegator { public static Map.Entry<String, String> encrypt(String strToEncrypt) throws SakuliCipherException { loadEnvironmentVariables(); Properties props = new Properties(); SakuliPropertyPlaceholderConfigurer.assignEncryptionProperties(props); CipherProperties cipherProps = CipherProperties.load(props); switch (cipherProps.getEncryptionMode()) { case CipherProperties.ENCRYPTION_MODE_ENVIRONMENT: return new AbstractMap.SimpleEntry<>("environment masterkey", new EnvironmentCipher(cipherProps).encrypt(strToEncrypt)); case CipherProperties.ENCRYPTION_MODE_INTERFACE: NetworkInterfaceCipher cipher = new NetworkInterfaceCipher(cipherProps); cipher.scanNetworkInterfaces(); return new AbstractMap.SimpleEntry<>("interface " + cipher.getInterfaceName(), cipher.encrypt(strToEncrypt)); default: throw new SakuliCipherException("unexpected error during encryption"); } } }
CipherDelegator { public static Map.Entry<String, String> encrypt(String strToEncrypt) throws SakuliCipherException { loadEnvironmentVariables(); Properties props = new Properties(); SakuliPropertyPlaceholderConfigurer.assignEncryptionProperties(props); CipherProperties cipherProps = CipherProperties.load(props); switch (cipherProps.getEncryptionMode()) { case CipherProperties.ENCRYPTION_MODE_ENVIRONMENT: return new AbstractMap.SimpleEntry<>("environment masterkey", new EnvironmentCipher(cipherProps).encrypt(strToEncrypt)); case CipherProperties.ENCRYPTION_MODE_INTERFACE: NetworkInterfaceCipher cipher = new NetworkInterfaceCipher(cipherProps); cipher.scanNetworkInterfaces(); return new AbstractMap.SimpleEntry<>("interface " + cipher.getInterfaceName(), cipher.encrypt(strToEncrypt)); default: throw new SakuliCipherException("unexpected error during encryption"); } }  }
CipherDelegator { public static Map.Entry<String, String> encrypt(String strToEncrypt) throws SakuliCipherException { loadEnvironmentVariables(); Properties props = new Properties(); SakuliPropertyPlaceholderConfigurer.assignEncryptionProperties(props); CipherProperties cipherProps = CipherProperties.load(props); switch (cipherProps.getEncryptionMode()) { case CipherProperties.ENCRYPTION_MODE_ENVIRONMENT: return new AbstractMap.SimpleEntry<>("environment masterkey", new EnvironmentCipher(cipherProps).encrypt(strToEncrypt)); case CipherProperties.ENCRYPTION_MODE_INTERFACE: NetworkInterfaceCipher cipher = new NetworkInterfaceCipher(cipherProps); cipher.scanNetworkInterfaces(); return new AbstractMap.SimpleEntry<>("interface " + cipher.getInterfaceName(), cipher.encrypt(strToEncrypt)); default: throw new SakuliCipherException("unexpected error during encryption"); } }  static Map.Entry<String, String> encrypt(String strToEncrypt); }
CipherDelegator { public static Map.Entry<String, String> encrypt(String strToEncrypt) throws SakuliCipherException { loadEnvironmentVariables(); Properties props = new Properties(); SakuliPropertyPlaceholderConfigurer.assignEncryptionProperties(props); CipherProperties cipherProps = CipherProperties.load(props); switch (cipherProps.getEncryptionMode()) { case CipherProperties.ENCRYPTION_MODE_ENVIRONMENT: return new AbstractMap.SimpleEntry<>("environment masterkey", new EnvironmentCipher(cipherProps).encrypt(strToEncrypt)); case CipherProperties.ENCRYPTION_MODE_INTERFACE: NetworkInterfaceCipher cipher = new NetworkInterfaceCipher(cipherProps); cipher.scanNetworkInterfaces(); return new AbstractMap.SimpleEntry<>("interface " + cipher.getInterfaceName(), cipher.encrypt(strToEncrypt)); default: throw new SakuliCipherException("unexpected error during encryption"); } }  static Map.Entry<String, String> encrypt(String strToEncrypt);  }