List of usage examples for org.bouncycastle.crypto.io DigestInputStream DigestInputStream
public DigestInputStream(InputStream stream, Digest digest)
From source file:com.github.horrorho.inflatabledonkey.file.FileStreamWriter.java
License:Open Source License
public static boolean copy(InputStream in, OutputStream out, Optional<XFileKey> keyCipher, Optional<byte[]> signature) throws IOException { Digest digest = signature.flatMap(FileSignature::type).orElse(FileSignature.ONE).newDigest(); DigestInputStream digestInputStream = new DigestInputStream(in, digest); IOUtils.copyLarge(decryptStream(digestInputStream, keyCipher), out, new byte[BUFFER_SIZE]); out.flush();/*from w w w . j a v a 2 s .c o m*/ return testSignature(digestInputStream.getDigest(), signature); }
From source file:com.stg.crypto.IODigestUtility.java
License:Open Source License
/** * Wraps the given {@link InputStream} against a digest * @param is input stream// w w w. ja v a 2 s . c o m * @return input stream */ public static DigestInputStream wrapDigestInputStream(GeneralDigest digest, InputStream is) { digest.reset(); return new DigestInputStream(is, digest); }
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();/* w w w. java2 s. com*/ //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); }
From source file:org.xwiki.crypto.internal.digest.BouncyCastleDigest.java
License:Open Source License
@Override public FilterInputStream getInputStream(InputStream is) { digest.reset(); return new DigestInputStream(is, digest); }