Search in sources :

Example 6 with EncryptedInputStream

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

the class EmailFolder method getMetadata.

private EmailMetadata getMetadata(File file) throws IOException, GeneralSecurityException, PasswordException {
    InputStream metadataStream = new BufferedInputStream(new EncryptedInputStream(new FileInputStream(file), passwordHolder));
    EmailMetadata metadata = new EmailMetadata(metadataStream);
    return metadata;
}
Also used : EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) BufferedInputStream(java.io.BufferedInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) InputStream(java.io.InputStream) EmailMetadata(i2p.bote.email.EmailMetadata) FileInputStream(java.io.FileInputStream)

Example 7 with EncryptedInputStream

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

the class MigrateTo028 method migrateIdentitiesIfNeeded.

private void migrateIdentitiesIfNeeded(Configuration configuration, PasswordHolder passwordHolder) throws FileNotFoundException, IOException, GeneralSecurityException, PasswordException {
    File identitiesFile = configuration.getIdentitiesFile();
    if (!identitiesFile.exists())
        return;
    BufferedReader input = null;
    try {
        InputStream encryptedStream = new EncryptedInputStream(new FileInputStream(identitiesFile), passwordHolder);
        input = new BufferedReader(new InputStreamReader(encryptedStream));
        // No PasswordException occurred, so read the input stream and call migrateIdentities() if needed
        List<String> lines = Util.readLines(encryptedStream);
        if (!isIdentitiesFileMigrated(lines))
            migrateIdentities(lines, configuration, passwordHolder);
    } finally {
        if (input != null)
            input.close();
    }
}
Also used : EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 8 with EncryptedInputStream

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

the class ExportableData method importFromFileDescriptor.

/**
 * Imports data from FileDescriptor.
 *
 * @param importFileDescriptor
 * @param password
 * @param append               Set to false if existing data should be dropped.
 * @param replace              Set to false to ignore duplicates, true to import and replace existing.
 * @return true if the import succeeded, false if no valid data was found.
 * @throws PasswordException        if the provided password is invalid.
 * @throws IOException
 * @throws GeneralSecurityException
 */
public boolean importFromFileDescriptor(FileDescriptor importFileDescriptor, String password, boolean append, boolean replace) throws PasswordException, IOException, GeneralSecurityException {
    initializeIfNeeded();
    InputStream importStream = new FileInputStream(importFileDescriptor);
    if (password != null)
        importStream = new EncryptedInputStream(importStream, password.getBytes());
    try {
        Properties properties = new Properties();
        properties.load(new InputStreamReader(importStream));
        if (loadFromProperties(properties, append, replace)) {
            // Save the new data
            save();
            return true;
        } else
            // No data found
            return false;
    } finally {
        importStream.close();
    }
}
Also used : EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) EncryptedInputStream(i2p.bote.fileencryption.EncryptedInputStream) InputStream(java.io.InputStream) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

EncryptedInputStream (i2p.bote.fileencryption.EncryptedInputStream)8 FileInputStream (java.io.FileInputStream)8 InputStream (java.io.InputStream)7 InputStreamReader (java.io.InputStreamReader)5 BufferedReader (java.io.BufferedReader)4 File (java.io.File)4 IOException (java.io.IOException)3 Properties (java.util.Properties)3 PasswordException (i2p.bote.fileencryption.PasswordException)2 SortedProperties (i2p.bote.util.SortedProperties)2 BufferedInputStream (java.io.BufferedInputStream)2 GeneralSecurityException (java.security.GeneralSecurityException)2 Email (i2p.bote.email.Email)1 EmailMetadata (i2p.bote.email.EmailMetadata)1 Contact (i2p.bote.packet.dht.Contact)1 FileNotFoundException (java.io.FileNotFoundException)1 ArrayList (java.util.ArrayList)1