public SmartDecryptingInputStream()

in src/java/org/apache/fulcrum/jce/crypto/SmartDecryptingInputStream.java [68:114]


    public SmartDecryptingInputStream(
        CryptoStreamFactory cryptoStreamFactory,
        InputStream is,
        char[] password )
        throws IOException, GeneralSecurityException
    {
        super( new byte[0] );

        byte[] content = null;
        byte[] plain = null;

        // store the data from the input stream

        ByteArrayOutputStream baosCipher = new ByteArrayOutputStream();
        ByteArrayOutputStream baosPlain = new ByteArrayOutputStream();
        this.copy( is, baosCipher );

        content = baosCipher.toByteArray();
        plain = content;

        if( this.isEncrypted(content) == true )
        {
            InputStream cis = null;
            ByteArrayInputStream bais = new ByteArrayInputStream(content);

            if( ( password != null ) && ( password.length > 0 ) )
            {
                cis = cryptoStreamFactory.getInputStream( bais, password );
            }
            else
            {
                cis = cryptoStreamFactory.getInputStream( bais );
            }

            copy( cis, baosPlain );
            plain = baosPlain.toByteArray();
        }

        // initialize the inherited instance

        if( plain != null )
        {
            this.buf = plain;
            this.pos = 0;
            this.count = buf.length;
        }
    }