@Test public void testEncryptLongArrayAes258Twofish256UnlimitedStrength() throws Exception { testEncrypt( TestFileUtil.createRandomArray(1024 * 1024), Arrays.asList( new CipherSpec[] { CipherSpecs.getCipherSpec(CipherSpecs.AES_256_GCM), CipherSpecs.getCipherSpec(CipherSpecs.TWOFISH_256_GCM) })); }
@Test public void testEncryptLongArrayAes128Twofish128() throws Exception { testEncrypt( TestFileUtil.createRandomArray(1024 * 1024), Arrays.asList( new CipherSpec[] { CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM), CipherSpecs.getCipherSpec(CipherSpecs.TWOFISH_128_GCM) })); }
@Test public void testEncryptShortArrayAes128Twofish128() throws Exception { testEncrypt( new byte[] {1, 2, 3, 4}, Arrays.asList( new CipherSpec[] { CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM), CipherSpecs.getCipherSpec(CipherSpecs.TWOFISH_128_GCM) })); }
public static InitOperationOptions createTestInitOperationOptions(String machineName) throws Exception { File tempLocalDir = TestFileUtil.createTempDirectoryInSystemTemp( createUniqueName("client-" + machineName, machineName)); File tempRepoDir = TestFileUtil.createTempDirectoryInSystemTemp(createUniqueName("repo", machineName)); tempLocalDir.mkdirs(); tempRepoDir.mkdirs(); RepoTO repoTO = createRepoTO(); // Create config TO ConfigTO configTO = new ConfigTO(); configTO.setMachineName(machineName + Math.abs(new Random().nextInt())); // Get Masterkey SaltedSecretKey masterKey = getMasterKey(); configTO.setMasterKey(masterKey); // Create connection TO Map<String, String> localConnectionSettings = new HashMap<String, String>(); localConnectionSettings.put("path", tempRepoDir.getAbsolutePath()); ConnectionTO connectionTO = new ConnectionTO(); connectionTO.setType("local"); connectionTO.setSettings(localConnectionSettings); configTO.setConnectionTO(connectionTO); InitOperationOptions operationOptions = new InitOperationOptions(); operationOptions.setLocalDir(tempLocalDir); operationOptions.setConfigTO(configTO); operationOptions.setRepoTO(repoTO); operationOptions.setEncryptionEnabled(cryptoEnabled); operationOptions.setCipherSpecs(CipherSpecs.getDefaultCipherSpecs()); operationOptions.setPassword(cryptoEnabled ? "some password" : null); return operationOptions; }
@Test public void testCreateDerivedKeys() throws InvalidKeySpecException, NoSuchAlgorithmException, NoSuchProviderException { SaltedSecretKey masterKey = createDummyMasterKey(); CipherSpec cipherSpec = CipherSpecs.getCipherSpec(CipherSpecs.AES_128_GCM); byte[] derivedKeySalt1 = new byte[] {1, 2, 3}; byte[] derivedKeySalt2 = new byte[] {1, 2, 3, 4}; SaltedSecretKey derivedKey1 = CipherUtil.createDerivedKey(masterKey, derivedKeySalt1, cipherSpec); SaltedSecretKey derivedKey2 = CipherUtil.createDerivedKey(masterKey, derivedKeySalt2, cipherSpec); logger.log(Level.INFO, "- Derived key 1: " + StringUtil.toHex(derivedKey1.getEncoded())); logger.log(Level.INFO, " with salt: " + StringUtil.toHex(derivedKey1.getSalt())); logger.log(Level.INFO, "- Derived key 2: " + StringUtil.toHex(derivedKey2.getEncoded())); logger.log(Level.INFO, " with salt: " + StringUtil.toHex(derivedKey2.getSalt())); assertEquals(128 / 8, derivedKey1.getEncoded().length); assertEquals(128 / 8, derivedKey2.getEncoded().length); assertFalse(Arrays.equals(derivedKey1.getSalt(), derivedKey2.getSalt())); assertFalse(Arrays.equals(derivedKey1.getEncoded(), derivedKey2.getEncoded())); }