@Test public void testEncryptionWithNoPublicKey() { try { encrypterManager.encrypt(PLAINTEXT.getBytes()); fail("Did not throw GeneralSecurityException"); } catch (GeneralSecurityException e) { } }
public synchronized byte[] encrypt(byte[] data) throws GeneralSecurityException { if (!isLoaded) { throw new GeneralSecurityException("public key is not loaded"); } byte[] ciphertext = encrypter.encrypt(data, null); return CapillaryCiphertext.newBuilder() .setKeychainUniqueId(capillaryPublicKey.getKeychainUniqueId()) .setKeySerialNumber((capillaryPublicKey.getSerialNumber())) .setIsAuthKey(capillaryPublicKey.getIsAuth()) .setCiphertext(ByteString.copyFrom(ciphertext)) .build().toByteArray(); }
EncrypterManager { public synchronized byte[] encrypt(byte[] data) throws GeneralSecurityException { if (!isLoaded) { throw new GeneralSecurityException("public key is not loaded"); } byte[] ciphertext = encrypter.encrypt(data, null); return CapillaryCiphertext.newBuilder() .setKeychainUniqueId(capillaryPublicKey.getKeychainUniqueId()) .setKeySerialNumber((capillaryPublicKey.getSerialNumber())) .setIsAuthKey(capillaryPublicKey.getIsAuth()) .setCiphertext(ByteString.copyFrom(ciphertext)) .build().toByteArray(); } }
EncrypterManager { public synchronized byte[] encrypt(byte[] data) throws GeneralSecurityException { if (!isLoaded) { throw new GeneralSecurityException("public key is not loaded"); } byte[] ciphertext = encrypter.encrypt(data, null); return CapillaryCiphertext.newBuilder() .setKeychainUniqueId(capillaryPublicKey.getKeychainUniqueId()) .setKeySerialNumber((capillaryPublicKey.getSerialNumber())) .setIsAuthKey(capillaryPublicKey.getIsAuth()) .setCiphertext(ByteString.copyFrom(ciphertext)) .build().toByteArray(); }  }
EncrypterManager { public synchronized byte[] encrypt(byte[] data) throws GeneralSecurityException { if (!isLoaded) { throw new GeneralSecurityException("public key is not loaded"); } byte[] ciphertext = encrypter.encrypt(data, null); return CapillaryCiphertext.newBuilder() .setKeychainUniqueId(capillaryPublicKey.getKeychainUniqueId()) .setKeySerialNumber((capillaryPublicKey.getSerialNumber())) .setIsAuthKey(capillaryPublicKey.getIsAuth()) .setCiphertext(ByteString.copyFrom(ciphertext)) .build().toByteArray(); }  synchronized void loadPublicKey(byte[] publicKey); synchronized byte[] encrypt(byte[] data); synchronized void clearPublicKey(); }
EncrypterManager { public synchronized byte[] encrypt(byte[] data) throws GeneralSecurityException { if (!isLoaded) { throw new GeneralSecurityException("public key is not loaded"); } byte[] ciphertext = encrypter.encrypt(data, null); return CapillaryCiphertext.newBuilder() .setKeychainUniqueId(capillaryPublicKey.getKeychainUniqueId()) .setKeySerialNumber((capillaryPublicKey.getSerialNumber())) .setIsAuthKey(capillaryPublicKey.getIsAuth()) .setCiphertext(ByteString.copyFrom(ciphertext)) .build().toByteArray(); }  synchronized void loadPublicKey(byte[] publicKey); synchronized byte[] encrypt(byte[] data); synchronized void clearPublicKey();  }