Search in sources :

Example 1 with ECIESKeyCrypter

use of com.sparrowwallet.drongo.crypto.ECIESKeyCrypter in project sparrow by sparrowwallet.

the class ECIESOutputStream method close.

@Override
public void close() throws IOException {
    super.close();
    byte[] unencrypted = ((ByteArrayOutputStream) out).toByteArray();
    ECIESKeyCrypter keyCrypter = new ECIESKeyCrypter();
    EncryptedData encryptedData = keyCrypter.encrypt(unencrypted, encryptionMagic, encryptionKey);
    ByteStreams.copy(new ByteArrayInputStream(encryptedData.getEncryptedBytes()), encryptedStream);
    encryptedStream.flush();
    encryptedStream.close();
}
Also used : ECIESKeyCrypter(com.sparrowwallet.drongo.crypto.ECIESKeyCrypter) EncryptedData(com.sparrowwallet.drongo.crypto.EncryptedData)

Example 2 with ECIESKeyCrypter

use of com.sparrowwallet.drongo.crypto.ECIESKeyCrypter in project sparrow by sparrowwallet.

the class ECIESInputStream method ensureDecrypted.

private synchronized void ensureDecrypted() throws IOException {
    if (!decrypted) {
        byte[] encryptedBytes = ByteStreams.toByteArray(in);
        in.close();
        ECIESKeyCrypter keyCrypter = new ECIESKeyCrypter();
        byte[] decryptedBytes = keyCrypter.decrypt(new EncryptedData(encryptionMagic, encryptedBytes, null, null), decryptionKey);
        in = new ByteArrayInputStream(decryptedBytes);
        decrypted = true;
    }
}
Also used : ECIESKeyCrypter(com.sparrowwallet.drongo.crypto.ECIESKeyCrypter) EncryptedData(com.sparrowwallet.drongo.crypto.EncryptedData)

Aggregations

ECIESKeyCrypter (com.sparrowwallet.drongo.crypto.ECIESKeyCrypter)2 EncryptedData (com.sparrowwallet.drongo.crypto.EncryptedData)2