List of usage examples for org.bouncycastle.crypto.io CipherInputStream CipherInputStream
public CipherInputStream(InputStream is, AEADBlockCipher cipher)
From source file:com.github.flbaue.jcrypttool.v1.DecryptionRunnable.java
License:Apache License
@Override public void run() { PaddedBufferedBlockCipher cipher;//from w ww .j a v a 2 s. c om byte[] key; byte[] iv; byte[] salt; try (InputStream fileInputStream = new BufferedInputStream( new FileInputStream(encryptionSettings.inputFile))) { cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new PKCS7Padding()); salt = extractSalt(fileInputStream); iv = extractIV(fileInputStream); key = generateKey(encryptionSettings.password, salt); KeyParameter keyParam = new KeyParameter(key); CipherParameters params = new ParametersWithIV(keyParam, iv); cipher.init(false, params); /* System.out.println(getClass().getName() + " salt:\t" + Base64.toBase64String(salt) + " (" + salt.length + " byte)"); System.out.println(getClass().getName() + " key:\t" + Base64.toBase64String(key) + " (" + key.length + " byte)"); System.out.println(getClass().getName() + " iv:\t\t" + Base64.toBase64String(iv) + " (" + iv.length + " byte)"); */ InputStream in = null; OutputStream out = null; try { in = new GZIPInputStream(new CipherInputStream(fileInputStream, cipher)); out = new BufferedOutputStream(new FileOutputStream(encryptionSettings.outputFile)); processStreams(in, out); } catch (IOException e) { throw new RuntimeException(e); } finally { closeStream(in); closeStream(out); } } catch (IOException e) { throw new RuntimeException(e); } }
From source file:com.github.flbaue.jcrypttool.v2.domain.AesEncryptionService.java
License:Apache License
@Override public InputStream decryptedInputStream(final Path path, final String password) throws IOException, DecryptionFailedException { try {/*from w w w .j a v a2 s. c o m*/ InputStream in = new BufferedInputStream(Files.newInputStream(path)); byte[] initBlock = readInitBlock(in); byte[] salt = extractSalt(initBlock); byte[] iv = extractIV(initBlock); byte[] key = generateKey(password, salt); PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), new PKCS7Padding()); KeyParameter keyParam = new KeyParameter(key); CipherParameters params = new ParametersWithIV(keyParam, iv); cipher.init(false, params); return new CipherInputStream(in, cipher); } catch (InvalidKeySpecException | NoSuchAlgorithmException e) { throw new DecryptionFailedException(e); } }
From source file:com.github.horrorho.inflatabledonkey.cache.StreamCryptor.java
License:Open Source License
public CipherInputStream newCipherInputStream(InputStream is, byte[] password) throws IOException { byte[] salt = IOUtils.readFully(is, saltLength); byte[] nonce = IOUtils.readFully(is, nonceLength); byte[] dk = kdf.apply(password, salt); GCMBlockCipher cipher = new GCMBlockCipher(new AESEngine()); AEADParameters parameters = new AEADParameters(new KeyParameter(dk), tagLength * 8, nonce); cipher.init(false, parameters);// w w w. j av a 2 s.c o m return new CipherInputStream(is, cipher); }
From source file:com.github.horrorho.inflatabledonkey.chunk.engine.ChunkListDecrypter.java
License:Open Source License
CipherInputStream cipherInputStream(InputStream inputStream, byte[] key, byte[] checksum) { CFBBlockCipher cipher = new CFBBlockCipher(new AESFastEngine(), 128); KeyParameter keyParameter = new KeyParameter(key); cipher.init(false, keyParameter);/*from w w w. j av a 2 s. co m*/ return new CipherInputStream(inputStream, cipher); }
From source file:com.github.horrorho.inflatabledonkey.file.FileStreamWriter.java
License:Open Source License
static InputStream decryptStream(InputStream in, XFileKey keyCipher) { BlockCipher cipher = keyCipher.ciphers().get(); cipher.init(false, new KeyParameter(keyCipher.key())); return new CipherInputStream(in, new BufferedBlockCipher(cipher)); }
From source file:com.hanhuy.keepassj.StandardAesEngine.java
License:Open Source License
private static InputStream CreateInputStream(InputStream s, boolean bEncrypt, byte[] pbKey, byte[] pbIV) { byte[] pbLocalIV = new byte[16]; System.arraycopy(pbIV, 0, pbLocalIV, 0, 16); byte[] pbLocalKey = new byte[32]; System.arraycopy(pbKey, 0, pbLocalKey, 0, 32); try {// www . j a v a2 s .com // Cipher r = Cipher.getInstance("AES/CBC/PKCS5Padding"); // IvParameterSpec ivspec = new IvParameterSpec(pbLocalIV); // SecretKeySpec keyspec = new SecretKeySpec(pbLocalKey, "AES"); // r.init(Cipher.DECRYPT_MODE, keyspec, ivspec); BlockCipher aes = AesEngines.createAesEngine(); KeyParameter key = new KeyParameter(pbLocalKey); ParametersWithIV iv = new ParametersWithIV(key, pbLocalIV); BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(aes)); cipher.init(false, iv); return new CipherInputStream(s, cipher); } catch (Exception e) { throw new IllegalStateException(e); } }
From source file:com.javacreed.api.secureproperties.bouncycastle.TwoFishCipherFactory.java
License:Apache License
@Override protected InputStream wrapInToCipheredInputStream(final InputStream in) throws Exception { final BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new TwofishEngine())); cipher.init(false, new KeyParameter(key.getBytes("UTF-8"))); final CipherInputStream stream = new CipherInputStream(in, cipher); return stream; }
From source file:com.raphfrk.craftproxyliter.LocalSocket.java
License:Open Source License
public void setAES() { BufferedBlockCipher in = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8)); in.init(false, new ParametersWithIV(new KeyParameter(this.ptc.getSecretKey().getEncoded()), this.ptc.getSecretKey().getEncoded(), 0, 16)); BufferedBlockCipher out = new BufferedBlockCipher(new CFBBlockCipher(new AESFastEngine(), 8)); out.init(true, new ParametersWithIV(new KeyParameter(this.ptc.getSecretKey().getEncoded()), this.ptc.getSecretKey().getEncoded(), 0, 16)); this.in = new DataInputStream(new CipherInputStream(this.in, in)); this.out = new DataOutputStream(new CipherOutputStream(this.out, out)); pin = new ProtocolInputStream(this.in, 255 * 16 * 1024); pout = new ProtocolOutputStream(this.out); }
From source file:de.tntinteractive.portalsammler.engine.CryptoHelper.java
License:Open Source License
public static CipherInputStream createAesDecryptStream(final InputStream is, final byte[] key, final SecureRandom srand) { final PaddedBufferedBlockCipher cipher = initAes(key, srand, false); return new CipherInputStream(is, cipher); }
From source file:edu.wisc.doit.tcrypt.BouncyCastleFileDecrypter.java
License:Apache License
@Override public InputStream decrypt(InputStream inputStream) throws InvalidCipherTextException, IOException, DecoderException { final TarArchiveInputStream tarInputStream = new TarArchiveInputStream(inputStream, FileEncrypter.ENCODING); final BufferedBlockCipher cipher = createCipher(tarInputStream); //Advance to the next entry in the tar file tarInputStream.getNextTarEntry();/*from w ww .jav a 2s. c o m*/ //Protect the underlying TAR stream from being closed by the cipher stream final CloseShieldInputStream is = new CloseShieldInputStream(tarInputStream); //Setup the decrypting cipher stream final CipherInputStream stream = new CipherInputStream(is, cipher); //Generate a digest of the decrypted data final GeneralDigest digest = this.createDigester(); final DigestInputStream digestInputStream = new DigestInputStream(stream, digest); return new DecryptingInputStream(digestInputStream, tarInputStream, digest); }