Package org.apache.xml.security.encryption

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


       
        String encAlgo = X509Util.getEncAlgo(elem);
        SecretKey key = WSSecurityUtil.prepareSecretKey(encAlgo, this.symmKey);
       
        // initialize Cipher ....
        XMLCipher xmlCipher = null;
        try {
            xmlCipher = XMLCipher.getInstance(encAlgo);
            xmlCipher.init(XMLCipher.DECRYPT_MODE, key);
        } catch (XMLEncryptionException e1) {
            throw new WSSecurityException(
                    WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, e1);
        }
       
        Node previousSibling = elem.getPreviousSibling();

        try {
            xmlCipher.doFinal(elem.getOwnerDocument(), elem, false);
        } catch (Exception e) {
            throw new WSSecurityException(WSSecurityException.FAILED_ENC_DEC,
                    null, null, e);
        }
       
View Full Code Here


    protected byte[] decryptPayload(Element root,
                                    byte[] secretKeyBytes,
                                    String symEncAlgo) throws WSSecurityException {
        SecretKey key = WSSecurityUtil.prepareSecretKey(symEncAlgo, secretKeyBytes);
        try {
            XMLCipher xmlCipher =
                EncryptionUtils.initXMLCipher(symEncAlgo, XMLCipher.DECRYPT_MODE, key);
            return xmlCipher.decryptToByteArray(root);
        } catch (XMLEncryptionException ex) {
            throw new WSSecurityException(
                WSSecurityException.UNSUPPORTED_ALGORITHM, null, null, ex
            );
        }
View Full Code Here

            addEncryptedKeyElement(encryptedDataElement, cert, encryptedSecretKey);
        }
              
        // encrypt payloadDoc
        XMLCipher xmlCipher =
            EncryptionUtils.initXMLCipher(symEncAlgo, XMLCipher.ENCRYPT_MODE, symmetricKey);
       
        Document result = xmlCipher.doFinal(payloadDoc, payloadDoc.getDocumentElement(), false);
        NodeList list = result.getElementsByTagNameNS(WSConstants.ENC_NS, "CipherValue");
        if (list.getLength() != 1) {
            throw new WSSecurityException("Payload CipherData is missing", null);
        }
        String cipherText = ((Element)list.item(0)).getTextContent().trim();
View Full Code Here

        if (content) {
            encData = (Element) encData.getParentNode();
            parent = encData.getParentNode();
        }

        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
            );
        }
       
        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

        Key encryptingKey,
        String keyTransportAlgorithm,
        X509Certificate wrappingCert,
        boolean content
    ) throws Exception {
        XMLCipher cipher = XMLCipher.getInstance(algorithm);
        cipher.init(XMLCipher.ENCRYPT_MODE, encryptingKey);

        if (wrappingCert != null) {
            XMLCipher newCipher = XMLCipher.getInstance(keyTransportAlgorithm);
            newCipher.init(XMLCipher.WRAP_MODE, wrappingCert.getPublicKey());

            EncryptedKey encryptedKey = newCipher.encryptKey(document, encryptingKey);
            // Create a KeyInfo for the EncryptedKey
            KeyInfo encryptedKeyKeyInfo = encryptedKey.getKeyInfo();
            if (encryptedKeyKeyInfo == null) {
                encryptedKeyKeyInfo = new KeyInfo(document);
                encryptedKeyKeyInfo.getElement().setAttributeNS(
View Full Code Here

        Key encryptingKey,
        String keyTransportAlgorithm,
        X509Certificate wrappingCert,
        boolean content
    ) throws Exception {
        XMLCipher cipher = XMLCipher.getInstance(algorithm);
        cipher.init(XMLCipher.ENCRYPT_MODE, encryptingKey);

        if (wrappingCert != null) {
            XMLCipher newCipher = XMLCipher.getInstance(keyTransportAlgorithm);
            newCipher.init(XMLCipher.WRAP_MODE, wrappingCert.getPublicKey());

            EncryptedKey encryptedKey = newCipher.encryptKey(document, encryptingKey);
            // Create a KeyInfo for the EncryptedKey
            KeyInfo encryptedKeyKeyInfo = encryptedKey.getKeyInfo();
            if (encryptedKeyKeyInfo == null) {
                encryptedKeyKeyInfo = new KeyInfo(document);
                encryptedKeyKeyInfo.getElement().setAttributeNS(
View Full Code Here

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

        WSDataRef dataRef = new WSDataRef(dataRefURI);
        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.FAILED_CHECK, null, null, ex);
        }
       
        if (parent.getLocalName().equals(WSConstants.ENCRYPTED_HEADER)
View Full Code Here

     * @param assertionElement
     * @param encryptedKey
     */
    private void encryptSAMLAssertion(Document doc, Element assertionElement,
            WSSecEncryptedKey encryptedKey) throws TrustException {
        XMLCipher xmlCipher = null;
        SecretKey secretKey = null;
        String xencEncryptedDataId = null;
        KeyInfo keyInfo = null;
        EncryptedData encData = null;
        try {
            xmlCipher = XMLCipher.getInstance(WSConstants.AES_256);
            secretKey = WSSecurityUtil.prepareSecretKey(WSConstants.AES_256, encryptedKey
                    .getEphemeralKey());
            xmlCipher.init(XMLCipher.ENCRYPT_MODE, secretKey);
            xencEncryptedDataId = "EncDataId-" + assertionElement.hashCode();

            keyInfo = new KeyInfo(doc);
            keyInfo.addUnknownElement(encryptedKey.getEncryptedKeyElement());

            encData = xmlCipher.getEncryptedData();
            encData.setId(xencEncryptedDataId);
            encData.setKeyInfo(keyInfo);
            xmlCipher.doFinal(doc, assertionElement, false);
        } catch (Exception e) {
            throw new TrustException(TrustException.REQUEST_FAILED, e);
        }
    }
View Full Code Here

    Element kiElem = null;
    Element encrKeyElem = null;
    EncryptedKeyProcessor encrKeyProcessor = null;
    SecretKey secretKey = null;
    XMLCipher cipher = null;
    Document doc = null;

    if (log.isDebugEnabled()) {
      log.debug("decryptingToken");
    }

    kiElem = (Element) encryptedToken.getElementsByTagNameNS(WSConstants.SIG_NS, "KeyInfo")
        .item(0);
    encrKeyElem = (Element) kiElem.getElementsByTagNameNS(WSConstants.ENC_NS,
        EncryptionConstants._TAG_ENCRYPTEDKEY).item(0);

    encrKeyProcessor = new EncryptedKeyProcessor();
    encrKeyProcessor.handleEncryptedKey(encrKeyElem, privKey);

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

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

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

    if (log.isDebugEnabled()) {
      log.debug("decryptingTokenDone");
    }
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();
  }
View Full Code Here

TOP

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

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.