Search in sources :

Example 1 with EncryptedOutputStream

use of i2p.bote.fileencryption.EncryptedOutputStream in project i2p.i2p-bote by i2p.

the class AddressBook method save.

public void save() throws IOException, PasswordException, GeneralSecurityException {
    initializeIfNeeded();
    OutputStream encryptedStream = new EncryptedOutputStream(new SecureFileOutputStream(addressFile), passwordHolder);
    try {
        Properties properties = saveToProperties();
        properties.store(new OutputStreamWriter(encryptedStream, "UTF-8"), null);
    } catch (IOException e) {
        log.error("Can't save email identities to file <" + addressFile.getAbsolutePath() + ">.", e);
        throw e;
    } finally {
        encryptedStream.close();
    }
}
Also used : EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) OutputStream(java.io.OutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) Properties(java.util.Properties) SortedProperties(i2p.bote.util.SortedProperties) EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream)

Example 2 with EncryptedOutputStream

use of i2p.bote.fileencryption.EncryptedOutputStream in project i2p.i2p-bote by i2p.

the class EmailFolder method saveMetadata.

private void saveMetadata(EmailMetadata metadata, File file) throws PasswordException, FileNotFoundException, IOException, GeneralSecurityException {
    log.info("Mail folder <" + storageDir + ">: storing metadata file: <" + file.getAbsolutePath() + ">");
    OutputStream emailOutputStream = new BufferedOutputStream(new EncryptedOutputStream(new SecureFileOutputStream(file), passwordHolder));
    try {
        metadata.writeTo(emailOutputStream);
    } catch (IOException e) {
        log.error("Can't write metadata to file <" + file.getAbsolutePath() + ">", e);
        throw e;
    } finally {
        if (emailOutputStream != null)
            emailOutputStream.close();
    }
    for (FolderListener listener : folderListeners) listener.elementUpdated();
}
Also used : EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) IOException(java.io.IOException) BufferedOutputStream(java.io.BufferedOutputStream) EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream)

Example 3 with EncryptedOutputStream

use of i2p.bote.fileencryption.EncryptedOutputStream in project i2p.i2p-bote by i2p.

the class EmailFolder method add.

/**
 * Stores an email in the folder. If an email with the same
 * message ID exists already, nothing happens.
 * @param email
 * @throws IOException
 * @throws MessagingException
 * @throws PasswordException
 * @throws GeneralSecurityException
 */
public void add(Email email) throws IOException, MessagingException, PasswordException, GeneralSecurityException {
    // check if an email exists already with that message id
    if (getEmailFile(email.getMessageID()).exists()) {
        log.debug("Not storing email because there is an existing one with the same message ID: <" + email.getMessageID() + ">");
        return;
    }
    // write out the email file
    File emailFile = getEmailFile(email);
    log.info("Mail folder <" + storageDir + ">: storing email file: <" + emailFile.getAbsolutePath() + ">");
    OutputStream emailOutputStream = new BufferedOutputStream(new EncryptedOutputStream(new SecureFileOutputStream(emailFile), passwordHolder));
    try {
        email.writeTo(emailOutputStream);
    } finally {
        emailOutputStream.close();
    }
    saveMetadata(email);
    for (FolderListener listener : folderListeners) listener.elementAdded(email.getMessageID());
}
Also used : EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream)

Example 4 with EncryptedOutputStream

use of i2p.bote.fileencryption.EncryptedOutputStream in project i2p.i2p-bote by i2p.

the class MigrateTo027 method encrypt.

private void encrypt(File oldFile, File newFile) throws IOException, PasswordException, GeneralSecurityException {
    InputStream inputStream = null;
    byte[] contents = null;
    try {
        inputStream = new FileInputStream(oldFile);
        contents = Util.readBytes(inputStream);
    } finally {
        if (inputStream != null)
            inputStream.close();
    }
    EncryptedOutputStream encryptedStream = null;
    try {
        OutputStream fileOutputStream = new FileOutputStream(newFile);
        encryptedStream = new EncryptedOutputStream(fileOutputStream, passwordCache);
        if (contents != null)
            encryptedStream.write(contents);
    } finally {
        if (encryptedStream != null)
            encryptedStream.close();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream) EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream)

Example 5 with EncryptedOutputStream

use of i2p.bote.fileencryption.EncryptedOutputStream in project i2p.i2p-bote by i2p.

the class MigrateTo026 method encrypt.

private void encrypt(File oldFile, File newFile) throws IOException, PasswordException, GeneralSecurityException {
    InputStream inputStream = null;
    byte[] contents = null;
    try {
        inputStream = new FileInputStream(oldFile);
        contents = Util.readBytes(inputStream);
    } finally {
        if (inputStream != null)
            inputStream.close();
    }
    EncryptedOutputStream encryptedStream = null;
    try {
        OutputStream fileOutputStream = new FileOutputStream(newFile);
        encryptedStream = new EncryptedOutputStream(fileOutputStream, passwordCache);
        if (contents != null)
            encryptedStream.write(contents);
    } finally {
        if (encryptedStream != null)
            encryptedStream.close();
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream) EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream)

Aggregations

EncryptedOutputStream (i2p.bote.fileencryption.EncryptedOutputStream)7 OutputStream (java.io.OutputStream)6 SecureFileOutputStream (net.i2p.util.SecureFileOutputStream)4 FileOutputStream (java.io.FileOutputStream)3 IOException (java.io.IOException)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Properties (java.util.Properties)3 SortedProperties (i2p.bote.util.SortedProperties)2 BufferedOutputStream (java.io.BufferedOutputStream)2 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 DerivedKey (i2p.bote.fileencryption.DerivedKey)1 PasswordCache (i2p.bote.fileencryption.PasswordCache)1 File (java.io.File)1