@Test public void TestEncryptFilename() { final FileNameCryptor mock = mock(FileNameCryptor.class); final CryptorCache cryptor = new CryptorCache(mock); when(mock.encryptFilename(any(), any(), any())).thenReturn(RandomStringUtils.randomAscii(10)); final String encrypted1 = cryptor.encryptFilename(CryptorCache.BASE32, "first", "id1".getBytes()); verify(mock, times(1)).encryptFilename(any(), any(), any()); assertEquals(encrypted1, cryptor.encryptFilename(CryptorCache.BASE32, "first", "id1".getBytes())); verify(mock, times(1)).encryptFilename(any(), any(), any()); assertEquals("first", cryptor.decryptFilename(CryptorCache.BASE32, encrypted1, "id1".getBytes())); verify(mock, times(1)).encryptFilename(any(), any(), any()); verifyNoMoreInteractions(mock); cryptor.encryptFilename(BaseEncoding.base64Url(), "first", "id1".getBytes()); verify(mock, times(2)).encryptFilename(any(), any(), any()); cryptor.encryptFilename(CryptorCache.BASE32, "second", "id1".getBytes()); verify(mock, times(3)).encryptFilename(any(), any(), any()); cryptor.encryptFilename(CryptorCache.BASE32, "first", "id2".getBytes()); verify(mock, times(4)).encryptFilename(any(), any(), any()); }
public String encryptFilename(final BaseEncoding encoding, final String cleartextName, final byte[] associatedData) { final CacheKey key = new CacheKey(encoding, cleartextName, associatedData); if(encryptCache.contains(key)) { return encryptCache.get(key); } final String ciphertextName = impl.encryptFilename(encoding, cleartextName, associatedData); encryptCache.put(key, ciphertextName); decryptCache.put(new CacheKey(encoding, ciphertextName, associatedData), cleartextName); return ciphertextName; }
CryptorCache { public String encryptFilename(final BaseEncoding encoding, final String cleartextName, final byte[] associatedData) { final CacheKey key = new CacheKey(encoding, cleartextName, associatedData); if(encryptCache.contains(key)) { return encryptCache.get(key); } final String ciphertextName = impl.encryptFilename(encoding, cleartextName, associatedData); encryptCache.put(key, ciphertextName); decryptCache.put(new CacheKey(encoding, ciphertextName, associatedData), cleartextName); return ciphertextName; } }
CryptorCache { public String encryptFilename(final BaseEncoding encoding, final String cleartextName, final byte[] associatedData) { final CacheKey key = new CacheKey(encoding, cleartextName, associatedData); if(encryptCache.contains(key)) { return encryptCache.get(key); } final String ciphertextName = impl.encryptFilename(encoding, cleartextName, associatedData); encryptCache.put(key, ciphertextName); decryptCache.put(new CacheKey(encoding, ciphertextName, associatedData), cleartextName); return ciphertextName; } CryptorCache(final FileNameCryptor impl); }
CryptorCache { public String encryptFilename(final BaseEncoding encoding, final String cleartextName, final byte[] associatedData) { final CacheKey key = new CacheKey(encoding, cleartextName, associatedData); if(encryptCache.contains(key)) { return encryptCache.get(key); } final String ciphertextName = impl.encryptFilename(encoding, cleartextName, associatedData); encryptCache.put(key, ciphertextName); decryptCache.put(new CacheKey(encoding, ciphertextName, associatedData), cleartextName); return ciphertextName; } CryptorCache(final FileNameCryptor impl); String hashDirectoryId(final String cleartextDirectoryId); String encryptFilename(final BaseEncoding encoding, final String cleartextName, final byte[] associatedData); String decryptFilename(final BaseEncoding encoding, final String ciphertextName, final byte[] associatedData); }
CryptorCache { public String encryptFilename(final BaseEncoding encoding, final String cleartextName, final byte[] associatedData) { final CacheKey key = new CacheKey(encoding, cleartextName, associatedData); if(encryptCache.contains(key)) { return encryptCache.get(key); } final String ciphertextName = impl.encryptFilename(encoding, cleartextName, associatedData); encryptCache.put(key, ciphertextName); decryptCache.put(new CacheKey(encoding, ciphertextName, associatedData), cleartextName); return ciphertextName; } CryptorCache(final FileNameCryptor impl); String hashDirectoryId(final String cleartextDirectoryId); String encryptFilename(final BaseEncoding encoding, final String cleartextName, final byte[] associatedData); String decryptFilename(final BaseEncoding encoding, final String ciphertextName, final byte[] associatedData); static final BaseEncoding BASE32; }