org.bouncycastle.crypto.io.CipherOutputStream Java Examples

The following examples show how to use org.bouncycastle.crypto.io.CipherOutputStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SAES256v01.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] encrypt(byte[] buffer) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try (CipherOutputStream cipherOutputStream = new CipherOutputStream(byteArrayOutputStream, encryptor)) {
        cipherOutputStream.write(buffer);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return byteArrayOutputStream.toByteArray();
}
 
Example #2
Source File: SAES256v01.java    From sfs with Apache License 2.0 5 votes vote down vote up
@Override
public byte[] decrypt(byte[] buffer) {
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    try (CipherOutputStream cipherOutputStream = new CipherOutputStream(byteArrayOutputStream, decryptor)) {
        cipherOutputStream.write(buffer);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    return byteArrayOutputStream.toByteArray();
}
 
Example #3
Source File: Downloader.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
public static OutputStream setupOutputStream(OutputStream os, String reference) {
    if (reference != null && reference.length() == 96) {
        byte[] keyAndIv = hexToBytes(reference);
        byte[] key = new byte[32];
        byte[] iv = new byte[16];
        System.arraycopy(keyAndIv, 0, iv, 0, 16);
        System.arraycopy(keyAndIv, 16, key, 0, 32);
        AEADBlockCipher cipher = new GCMBlockCipher(new AESEngine());
        cipher.init(false, new AEADParameters(new KeyParameter(key), 128, iv));
        return new CipherOutputStream(os, cipher);
    } else {
        return os;
    }
}
 
Example #4
Source File: StreamCryptor.java    From InflatableDonkey with MIT License 5 votes vote down vote up
public CipherOutputStream newCipherOutputStream(OutputStream os, byte[] password) throws IOException {
    byte[] salt = randomBytes(saltLength);
    byte[] nonce = randomBytes(nonceLength);
    os.write(salt);
    os.write(nonce);
    byte[] dk = kdf.apply(password, salt);
    GCMBlockCipher cipher = new GCMBlockCipher(new AESEngine());
    AEADParameters parameters = new AEADParameters(new KeyParameter(dk), tagLength * 8, nonce);
    cipher.init(true, parameters);
    return new CipherOutputStream(os, cipher);
}
 
Example #5
Source File: CryptManager.java    From FishingBot with GNU General Public License v3.0 4 votes vote down vote up
public static OutputStream encryptOuputStream(SecretKey par0SecretKey, OutputStream par1OutputStream) {
    return new CipherOutputStream(par1OutputStream, createBufferedBlockCipher(true, par0SecretKey));
}
 
Example #6
Source File: EncryptionUtil.java    From AIBot with GNU General Public License v3.0 4 votes vote down vote up
public static OutputStream encryptOutputStream(OutputStream outputStream, SecretKey key) {
	return new CipherOutputStream(outputStream, createBlockCipher(key, true));
}
 
Example #7
Source File: CipherEndableWriteStream.java    From sfs with Apache License 2.0 4 votes vote down vote up
public CipherEndableWriteStream(BufferEndableWriteStream delegate, AEADBlockCipher cipher) {
    this.delegate = delegate;
    this.bufferEndableWriteStreamOutputStream = new BufferEndableWriteStreamOutputStream(delegate);
    this.outputStream = new CipherOutputStream(bufferEndableWriteStreamOutputStream, cipher);
}
 
Example #8
Source File: CipherEndableWriteStream.java    From sfs with Apache License 2.0 4 votes vote down vote up
public CipherEndableWriteStream(BufferEndableWriteStream delegate, Cipher cipher) {
    this.delegate = delegate;
    this.bufferEndableWriteStreamOutputStream = new BufferEndableWriteStreamOutputStream(delegate);
    this.outputStream = new javax.crypto.CipherOutputStream(bufferEndableWriteStreamOutputStream, cipher);
}
 
Example #9
Source File: CipherReadStream.java    From sfs with Apache License 2.0 4 votes vote down vote up
public CipherReadStream(ReadStream<Buffer> delegate, AEADBlockCipher aeadBlockCipher) {
    this.delegate = delegate;
    this.readStreamDataHandlerOutputStream = new ReadStreamDataHandlerOutputStream(dataHandler);
    this.cipherOutputStream = new CipherOutputStream(readStreamDataHandlerOutputStream, aeadBlockCipher);
}
 
Example #10
Source File: CipherReadStream.java    From sfs with Apache License 2.0 4 votes vote down vote up
public CipherReadStream(ReadStream<Buffer> delegate, Cipher cipher) {
    this.delegate = delegate;
    this.readStreamDataHandlerOutputStream = new ReadStreamDataHandlerOutputStream(dataHandler);
    this.cipherOutputStream = new javax.crypto.CipherOutputStream(readStreamDataHandlerOutputStream, cipher);
}
 
Example #11
Source File: EncryptionUtil.java    From DarkBot with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static OutputStream encryptOutputStream(OutputStream outputStream, SecretKey key) {
	return new CipherOutputStream(outputStream, createBlockCipher(key, true));
}