Class DecryptingInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class DecryptingInputStream
    extends java.io.InputStream
    An input stream that encrypts data produced by a EncryptingOutputStream. A lightweight yet secure hybrid encryption scheme is used. A random symmetric key is decrypted using the receiver's private key. The supplied data is then decrypted using the symmetric key and read on a streaming basis. When the end of the stream is reached or the stream is closed, a HMAC checksum of the entire stream contents is validated.
    • Constructor Summary

      Constructors 
      Constructor Description
      DecryptingInputStream​(java.io.InputStream wrapped, java.security.PrivateKey privKey)
      Constructs a DecryptingInputStream using default symmetric encryption parameters.
      DecryptingInputStream​(java.io.InputStream wrapped, java.security.PrivateKey privKey, java.lang.String algorithm, java.lang.String mode, java.lang.String padding)
      Constructs a DecryptingInputStream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      int read()  
      int read​(byte[] b)  
      int read​(byte[] b, int off, int len)  
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • DecryptingInputStream

        public DecryptingInputStream​(java.io.InputStream wrapped,
                                     java.security.PrivateKey privKey)
                              throws java.io.IOException,
                                     java.security.NoSuchAlgorithmException,
                                     javax.crypto.NoSuchPaddingException,
                                     java.security.InvalidKeyException,
                                     javax.crypto.IllegalBlockSizeException,
                                     javax.crypto.BadPaddingException,
                                     java.security.InvalidAlgorithmParameterException,
                                     java.security.NoSuchProviderException
        Constructs a DecryptingInputStream using default symmetric encryption parameters.
        Parameters:
        wrapped - the input stream to decrypt
        privKey - the receiver's private key for decrypting the symmetric key
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        java.security.NoSuchAlgorithmException - the no such algorithm exception
        javax.crypto.NoSuchPaddingException - the no such padding exception
        java.security.InvalidKeyException - the invalid key exception
        javax.crypto.IllegalBlockSizeException - the illegal block size exception
        javax.crypto.BadPaddingException - the bad padding exception
        java.security.InvalidAlgorithmParameterException - the invalid algorithm parameter exception
        java.security.NoSuchProviderException - the no such provider exception
      • DecryptingInputStream

        public DecryptingInputStream​(java.io.InputStream wrapped,
                                     java.security.PrivateKey privKey,
                                     java.lang.String algorithm,
                                     java.lang.String mode,
                                     java.lang.String padding)
                              throws java.io.IOException,
                                     java.security.NoSuchAlgorithmException,
                                     javax.crypto.NoSuchPaddingException,
                                     java.security.InvalidKeyException,
                                     javax.crypto.IllegalBlockSizeException,
                                     javax.crypto.BadPaddingException,
                                     java.security.InvalidAlgorithmParameterException,
                                     java.security.NoSuchProviderException
        Constructs a DecryptingInputStream.
        Parameters:
        wrapped - the input stream to decrypt
        privKey - the receiver's private key for decrypting the symmetric key
        algorithm - encryption algorithm (e.g. "AES")
        mode - encryption mode (e.g. "CBC")
        padding - padding scheme (e.g. "PKCS5PADDING")
        Throws:
        java.io.IOException - Signals that an I/O exception has occurred.
        java.security.NoSuchAlgorithmException - the no such algorithm exception
        javax.crypto.NoSuchPaddingException - the no such padding exception
        java.security.InvalidKeyException - the invalid key exception
        javax.crypto.IllegalBlockSizeException - the illegal block size exception
        javax.crypto.BadPaddingException - the bad padding exception
        java.security.InvalidAlgorithmParameterException - the invalid algorithm parameter exception
        java.security.NoSuchProviderException - the no such provider exception
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException