Package javax.crypto

Examples of javax.crypto.CipherOutputStream


            if(cipher == null){
                initCipher();
            }
            //Base64OutputStream bos = new Base64OutputStream(outputStream);
            //TODO :: Wrap outputstream with base64 encoder
            CipherOutputStream cos = new CipherOutputStream(outputStream,cipher);
            //BufferedStreamWriter bsw = new BufferedStreamWriter(cos);
            byte [] iv = cipher.getIV();
            outputStream.write(iv);
            outputStream.flush();
            if(data instanceof JAXBData){
                ((JAXBData)data).writeTo(cos);// write in chucks
            }else if(data instanceof StreamWriterData){
                StAXC14nCanonicalizerImpl exc14n = new StAXEXC14nCanonicalizerImpl();
                //((StAXEXC14nCanonicalizerImpl)exc14n).setInclusivePrefixList(new ArrayList());
                NamespaceContextEx nsEx = ((StreamWriterData)data).getNamespaceContext();
                Iterator<Binding> iter = nsEx.iterator();
                while(iter.hasNext()){
                    Binding binding = iter.next();
                    exc14n.writeNamespace(binding.getPrefix(),binding.getNamespaceURI());
                }
                if(logger.isLoggable(Level.FINEST)){
                    exc14n.setStream(new ByteArrayOutputStream());
                }else{
                    exc14n.setStream(cos);
                }
                try {
                    ((StreamWriterData)data).write(exc14n);
                    if(logger.isLoggable(Level.FINEST)){
                        byte [] cd=((ByteArrayOutputStream)exc14n.getOutputStream()).toByteArray();
                        logger.log(Level.FINEST, LogStringsMessages.WSS_1951_ENCRYPTED_DATA_VALUE(new String(cd)));
                        cos.write(cd);
                    }
                } catch (javax.xml.stream.XMLStreamException ex) {
                    logger.log(Level.SEVERE, LogStringsMessages.WSS_1908_ERROR_WRITING_ENCRYPTEDDATA(),ex);
                }
            }
           
            cos.flush();
            cos.close();
        } catch (NoSuchAlgorithmException ex) {
            logger.log(Level.SEVERE, LogStringsMessages.WSS_1909_UNSUPPORTED_DATAENCRYPTION_ALGORITHM(getAlgorithm()), ex);
            throw new XWSSecurityRuntimeException("Unable to compute CipherValue as "+getAlgorithm()+" is not supported", ex);
        } catch (javax.crypto.NoSuchPaddingException ex) {
            logger.log(Level.SEVERE, LogStringsMessages.WSS_1905_ERROR_INITIALIZING_CIPHER(), ex);
View Full Code Here


     */
    public CipherOutputStream encrypt(OutputStream os) throws InvalidKeyException,
        InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException
    {
        Cipher cipher = initEncryptModeCipher();
        return new CipherOutputStream(os, cipher);
    }
View Full Code Here

     */
    public CipherOutputStream decrypt(OutputStream os) throws InvalidKeyException,
        InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException
    {
        Cipher cipher = initDecryptModeCipher();
        return new CipherOutputStream(os, cipher);
    }
View Full Code Here

     */
    public CipherOutputStream encrypt(OutputStream os) throws InvalidKeyException,
        InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException
    {
        Cipher cipher = initEncryptModeCipher();
        return new CipherOutputStream(os, cipher);
    }
View Full Code Here

     */
    public CipherOutputStream decrypt(OutputStream os) throws InvalidKeyException,
        InvalidAlgorithmParameterException, NoSuchAlgorithmException, NoSuchPaddingException
    {
        Cipher cipher = initDecryptModeCipher();
        return new CipherOutputStream(os, cipher);
    }
View Full Code Here

                    ciphers = new CipherPair(cipherTransformation);
                }
            } catch (GeneralSecurityException e) {
                throw new IOException(e.getMessage(), e);
            }
            out = new CipherOutputStream(out, ciphers.getEncryptor()) {
                boolean closed;
                public void close() throws IOException {
                    if (!closed) {
                        super.close();
                        closed = true;
View Full Code Here

        Cipher desCipher = Cipher.getInstance(cipher);
        desCipher.init(Cipher.ENCRYPT_MODE, secretKey);

        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        CipherOutputStream cos = new CipherOutputStream(bos, desCipher);
        cos.write(toCrypt);
        cos.close();
        bos.close();

        byte[] cypherBytes = bos.toByteArray();
        return Base64.encodeBytes(cypherBytes);
    }
View Full Code Here

        /** {@inheritDoc} */
        public OutputStream applyFilter(OutputStream out) throws IOException {
            byte[] key = createEncryptionKey(streamNumber, streamGeneration);
            Cipher cipher = initCipher(key);
            return new CipherOutputStream(out, cipher);
        }
View Full Code Here

    @Override
    public OutputStream getOutputStream() throws JizzBlobException {
        logger.trace("Wrapping OutputStream in a CipherOutputStream using key "
                + "'{}' and a BufferedOutputStream", key);
        return new CipherOutputStream(new BufferedOutputStream(
                writer.getOutputStream()), makeCipher(key, Cipher.ENCRYPT_MODE));
    }
View Full Code Here

       
        /**
         * @see org.apache.fop.pdf.PDFFilter#applyFilter(OutputStream)
         */
        public OutputStream applyFilter(OutputStream out) throws IOException {
            return new CipherOutputStream(out,
                    encryption.initCipher(number, generation));
        }
View Full Code Here

TOP

Related Classes of javax.crypto.CipherOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.