Package org.apache.xml.security.encryption

Examples of org.apache.xml.security.encryption.XMLCipher


    SecretKey secretKey = WSSecurityUtil.prepareSecretKey(
        EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128, encrKeyProcessor
            .getDecryptedBytes());

    XMLCipher cipher = XMLCipher.getInstance();
    cipher.init(XMLCipher.DECRYPT_MODE, secretKey);

    Document doc = cipher.doFinal(encryptedToken.getOwnerDocument(), encryptedToken);

    return doc.getDocumentElement();
  }
View Full Code Here


            SecretKey secretKey = WSSecurityUtil.prepareSecretKey(
                    EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128, encrKeyProcessor
                            .getDecryptedBytes());

            XMLCipher cipher = XMLCipher.getInstance();
            cipher.init(XMLCipher.DECRYPT_MODE, secretKey);

            Document doc = cipher.doFinal(encryptedToken.getOwnerDocument(), encryptedToken);

            return doc.getDocumentElement();
        } catch (Exception e) {
            log.error("error occured while decryptng the token", e);
            throw e;
View Full Code Here

    public void createEncryptedData(String algorithm, Key key, Element element)
            throws XKMSException {
        try {

            Document doc = element.getOwnerDocument();
            XMLCipher xmlCipher = XMLCipher.getInstance(algorithm);
            xmlCipher.init(XMLCipher.ENCRYPT_MODE, key);
            xmlCipher.doFinal(doc, element, true);

        } catch (Exception e) {
            e.printStackTrace();
            throw new XKMSException(e);
        }
View Full Code Here

        }
    }

    public void decryptData(Key key, Document doc) throws XKMSException {
        try {
            XMLCipher xmlCipher = XMLCipher.getInstance();
            xmlCipher.init(XMLCipher.DECRYPT_MODE, key);
            xmlCipher.doFinal(doc, encryptedData, true);

            OMElement rsaKeyPairElem = ((OMElement) encryptedData)
                    .getFirstChildWithName(XKMS2Constants.Q_ELEM_RSA_KEY_PAIR);
            rsaKeyPair = (RSAKeyPair) RSAKeyPairTypeBuilder.INSTANCE
                    .buildElement(rsaKeyPairElem);
View Full Code Here

        String algorithm,
        SecretKey secretKey,
        Key wrappingKey,
        Document document
    ) throws Exception {
        XMLCipher cipher = XMLCipher.getInstance(algorithm);
        cipher.init(XMLCipher.DECRYPT_MODE, secretKey);
        if (wrappingKey != null) {
            cipher.setKEK(wrappingKey);
        }
       
        NodeList nodeList = document.getElementsByTagNameNS(
                XMLSecurityConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
                XMLSecurityConstants.TAG_xenc_EncryptedData.getLocalPart()
            );
        Element ee = (Element)nodeList.item(0);
        return cipher.doFinal(document, ee);
    }
View Full Code Here

    protected void doDOMEncryptionOutbound(File file, int tagCount) throws Exception {

        DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
        Document document = builder.parse(file);

        XMLCipher cipher = XMLCipher.getInstance("http://www.w3.org/2001/04/xmlenc#aes256-cbc");
        cipher.init(XMLCipher.ENCRYPT_MODE, encryptionSymKey);
        document = cipher.doFinal(document, document.getDocumentElement());

        XMLUtils.outputDOM(document, new BufferedOutputStream(new FileOutputStream(new File(getTmpFilePath(), "encryption-dom-" + tagCount + ".xml"))));
    }
View Full Code Here

    protected void doDOMDecryptionInbound(File file, int tagCount) throws Exception {

        DocumentBuilder builder = XMLUtils.createDocumentBuilder(false);
        Document document = builder.parse(file);

        XMLCipher cipher = XMLCipher.getInstance("http://www.w3.org/2001/04/xmlenc#aes256-cbc");
        cipher.init(XMLCipher.DECRYPT_MODE, encryptionSymKey);
        cipher.doFinal(document, document.getDocumentElement());
    }
View Full Code Here

     * Decrypt using DOM API
     */
    private Document decryptElementDOM(Document doc, Key rsaKey, X509Certificate rsaCert) throws Exception {

        // Create the XMLCipher element
        XMLCipher cipher = XMLCipher.getInstance();

        // Need to pre-load the Encrypted Data so we can get the key info
        Element ee =
                (Element) doc.getElementsByTagNameNS(
                        "http://www.w3.org/2001/04/xmlenc#", "EncryptedData"
                ).item(0);
        cipher.init(XMLCipher.DECRYPT_MODE, null);
        EncryptedData encryptedData = cipher.loadEncryptedData(doc, ee);

        KeyInfo ki = encryptedData.getKeyInfo();
        EncryptedKey encryptedKey = ki.itemEncryptedKey(0);

        XMLCipher cipher2 = XMLCipher.getInstance();
        cipher2.init(XMLCipher.UNWRAP_MODE, rsaKey);
        Key key =
                cipher2.decryptKey(
                        encryptedKey, encryptedData.getEncryptionMethod().getAlgorithm()
                );

        cipher.init(XMLCipher.DECRYPT_MODE, key);
        Document dd = cipher.doFinal(doc, ee);
View Full Code Here

        String encryptionAlgorithm,
        List<WSEncryptionPart> references,
        CallbackLookup callbackLookup
    ) throws WSSecurityException {

        XMLCipher xmlCipher = null;
        try {
            xmlCipher = XMLCipher.getInstance(encryptionAlgorithm);
        } catch (XMLEncryptionException ex) {
            throw new WSSecurityException(
                WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, ex
View Full Code Here

        String dataRefURI,
        Element encData,
        SecretKey symmetricKey,
        String symEncAlgo
    ) throws WSSecurityException {
        XMLCipher xmlCipher = null;
        try {
            xmlCipher = XMLCipher.getInstance(symEncAlgo);
            xmlCipher.setSecureValidation(true);
            xmlCipher.init(XMLCipher.DECRYPT_MODE, symmetricKey);
        } catch (XMLEncryptionException ex) {
            throw new WSSecurityException(
                WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, ex
            );
        }

        WSDataRef dataRef = new WSDataRef();
        dataRef.setWsuId(dataRefURI);
        dataRef.setAlgorithm(symEncAlgo);
        boolean content = X509Util.isContent(encData);
        dataRef.setContent(content);
       
        Node parent = encData.getParentNode();
        Node previousSibling = encData.getPreviousSibling();
        if (content) {
            encData = (Element) encData.getParentNode();
            parent = encData.getParentNode();
        }
       
        try {
            xmlCipher.doFinal(doc, encData, content);
        } catch (Exception ex) {
            throw new WSSecurityException(WSSecurityException.ErrorCode.FAILED_CHECK, ex);
        }
       
        if (parent.getLocalName().equals(WSConstants.ENCRYPTED_HEADER)
View Full Code Here

TOP

Related Classes of org.apache.xml.security.encryption.XMLCipher

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.