Search in sources :

Example 6 with EncryptedOutputStream

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

the class Identities method save.

/**
 * Saves all identities to file.
 */
public void save() throws IOException, GeneralSecurityException, PasswordException {
    initializeIfNeeded();
    OutputStream encryptedStream = new EncryptedOutputStream(new SecureFileOutputStream(identitiesFile), 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 <" + identitiesFile.getAbsolutePath() + ">.", e);
        throw e;
    } finally {
        encryptedStream.close();
    }
}
Also used : EncryptedOutputStream(i2p.bote.fileencryption.EncryptedOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) 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 7 with EncryptedOutputStream

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

the class ExportableData method export.

public void export(OutputStream exportStream, String password) throws IOException, GeneralSecurityException, PasswordException {
    initializeIfNeeded();
    OutputStreamWriter writer;
    if (password != null) {
        // Use same salt and parameters as the on-disk files
        PasswordCache cache = new PasswordCache(I2PBote.getInstance().getConfiguration());
        cache.setPassword(password.getBytes());
        DerivedKey derivedKey = cache.getKey();
        writer = new OutputStreamWriter(new EncryptedOutputStream(exportStream, derivedKey), "UTF-8");
    } else
        writer = new OutputStreamWriter(exportStream, "UTF-8");
    Properties properties = saveToProperties();
    properties.store(writer, null);
    // If a password was provided, this call triggers the encryption
    writer.close();
}
Also used : PasswordCache(i2p.bote.fileencryption.PasswordCache) OutputStreamWriter(java.io.OutputStreamWriter) Properties(java.util.Properties) DerivedKey(i2p.bote.fileencryption.DerivedKey) 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