@Test public void TestDecryptFilename() { final FileNameCryptor mock = mock(FileNameCryptor.class); final CryptorCache cryptor = new CryptorCache(mock); when(mock.decryptFilename(any(), any(), any())).thenReturn(RandomStringUtils.randomAscii(10)); final String decrypted1 = cryptor.decryptFilename(CryptorCache.BASE32, "first", "id1".getBytes()); verify(mock, times(1)).decryptFilename(any(), any(), any()); assertEquals(decrypted1, cryptor.decryptFilename(CryptorCache.BASE32, "first", "id1".getBytes())); verify(mock, times(1)).decryptFilename(any(), any(), any()); assertEquals("first", cryptor.encryptFilename(CryptorCache.BASE32, decrypted1, "id1".getBytes())); verify(mock, times(1)).decryptFilename(any(), any(), any()); verifyNoMoreInteractions(mock); cryptor.decryptFilename(BaseEncoding.base64Url(), "first", "id1".getBytes()); verify(mock, times(2)).decryptFilename(any(), any(), any()); cryptor.decryptFilename(CryptorCache.BASE32, "second", "id1".getBytes()); verify(mock, times(3)).decryptFilename(any(), any(), any()); cryptor.decryptFilename(CryptorCache.BASE32, "first", "id2".getBytes()); verify(mock, times(4)).decryptFilename(any(), any(), any()); }
public String decryptFilename(final BaseEncoding encoding, final String ciphertextName, final byte[] associatedData) throws AuthenticationFailedException { final CacheKey key = new CacheKey(encoding, ciphertextName, associatedData); if(decryptCache.contains(key)) { return decryptCache.get(key); } final String cleartextName = impl.decryptFilename(encoding, ciphertextName, associatedData); decryptCache.put(key, cleartextName); encryptCache.put(new CacheKey(encoding, cleartextName, associatedData), ciphertextName); return cleartextName; }
CryptorCache { public String decryptFilename(final BaseEncoding encoding, final String ciphertextName, final byte[] associatedData) throws AuthenticationFailedException { final CacheKey key = new CacheKey(encoding, ciphertextName, associatedData); if(decryptCache.contains(key)) { return decryptCache.get(key); } final String cleartextName = impl.decryptFilename(encoding, ciphertextName, associatedData); decryptCache.put(key, cleartextName); encryptCache.put(new CacheKey(encoding, cleartextName, associatedData), ciphertextName); return cleartextName; } }
CryptorCache { public String decryptFilename(final BaseEncoding encoding, final String ciphertextName, final byte[] associatedData) throws AuthenticationFailedException { final CacheKey key = new CacheKey(encoding, ciphertextName, associatedData); if(decryptCache.contains(key)) { return decryptCache.get(key); } final String cleartextName = impl.decryptFilename(encoding, ciphertextName, associatedData); decryptCache.put(key, cleartextName); encryptCache.put(new CacheKey(encoding, cleartextName, associatedData), ciphertextName); return cleartextName; } CryptorCache(final FileNameCryptor impl); }
CryptorCache { public String decryptFilename(final BaseEncoding encoding, final String ciphertextName, final byte[] associatedData) throws AuthenticationFailedException { final CacheKey key = new CacheKey(encoding, ciphertextName, associatedData); if(decryptCache.contains(key)) { return decryptCache.get(key); } final String cleartextName = impl.decryptFilename(encoding, ciphertextName, associatedData); decryptCache.put(key, cleartextName); encryptCache.put(new CacheKey(encoding, cleartextName, associatedData), ciphertextName); return cleartextName; } 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 decryptFilename(final BaseEncoding encoding, final String ciphertextName, final byte[] associatedData) throws AuthenticationFailedException { final CacheKey key = new CacheKey(encoding, ciphertextName, associatedData); if(decryptCache.contains(key)) { return decryptCache.get(key); } final String cleartextName = impl.decryptFilename(encoding, ciphertextName, associatedData); decryptCache.put(key, cleartextName); encryptCache.put(new CacheKey(encoding, cleartextName, associatedData), ciphertextName); return cleartextName; } 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; }