/** * Looks up an {@link EmailIdentity} that has the same public encryption key and the * same public signing key as a given {@link EmailDestination}.<br/> * Returns <code>null</code> if nothing is found. * @param destination * @throws PasswordException * @throws GeneralSecurityException * @throws IOException */ public EmailIdentity get(EmailDestination destination) throws PasswordException, IOException, GeneralSecurityException { initializeIfNeeded(); if (identities == null) return null; for (EmailIdentity identity: identities) if (identity.getPublicEncryptionKey().equals(destination.getPublicEncryptionKey()) && identity.getPublicSigningKey().equals(destination.getPublicSigningKey())) return identity; return null; }
/** * Creates an <code>EncryptedEmailPacket</code> from an <code>UnencryptedEmailPacket</code>. * The public key of <code>emailDestination</code> is used for encryption. * The store time is set to <code>0</code>. * @param unencryptedPacket * @param emailDestination * @throws GeneralSecurityException If an error occurred during encryption */ public EncryptedEmailPacket(UnencryptedEmailPacket unencryptedPacket, EmailDestination emailDestination) throws GeneralSecurityException { storeTime = 0; byte[] delAuthorizationBytes = unencryptedPacket.getDeleteAuthorization().toByteArray(); delVerificationHash = SHA256Generator.getInstance().calculateHash(delAuthorizationBytes); cryptoImpl = emailDestination.getCryptoImpl(); encryptedData = cryptoImpl.encrypt(unencryptedPacket.toByteArray(), emailDestination.getPublicEncryptionKey()); dhtKey = getDhtKey(); }