当前位置: 首页>>代码示例>>Java>>正文


Java EncryptionConstants类代码示例

本文整理汇总了Java中org.apache.xml.security.utils.EncryptionConstants的典型用法代码示例。如果您正苦于以下问题:Java EncryptionConstants类的具体用法?Java EncryptionConstants怎么用?Java EncryptionConstants使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EncryptionConstants类属于org.apache.xml.security.utils包,在下文中一共展示了EncryptionConstants类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: encryptAssertion

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
private EncryptedAssertion encryptAssertion(Assertion assertion) {
    EncryptionParameters encryptionParameters = new EncryptionParameters();
    encryptionParameters.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);

    KeyEncryptionParameters keyEncryptionParameters = new KeyEncryptionParameters();
    keyEncryptionParameters.setEncryptionCredential(SPCredentials.getCredential());
    keyEncryptionParameters.setAlgorithm(EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSAOAEP);

    Encrypter encrypter = new Encrypter(encryptionParameters, keyEncryptionParameters);
    encrypter.setKeyPlacement(Encrypter.KeyPlacement.INLINE);

    try {
        EncryptedAssertion encryptedAssertion = encrypter.encrypt(assertion);
        return encryptedAssertion;
    } catch (EncryptionException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:rasmusson,项目名称:webprofile-ref-project,代码行数:19,代码来源:ArtifactResolutionServlet.java

示例2: encryptAssertion

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
/**
 * 加密断言
 */
private EncryptedAssertion encryptAssertion(Assertion assertion) {
    DataEncryptionParameters encryptionParameters = new DataEncryptionParameters();
    encryptionParameters.setAlgorithm(EncryptionConstants.ALGO_ID_BLOCKCIPHER_AES128);

    KeyEncryptionParameters keyEncryptionParameters = new KeyEncryptionParameters();
    keyEncryptionParameters.setEncryptionCredential(SPCredentials.getCredential());
    keyEncryptionParameters.setAlgorithm(EncryptionConstants.ALGO_ID_KEYTRANSPORT_RSAOAEP);

    Encrypter encrypter = new Encrypter(encryptionParameters, keyEncryptionParameters);
    encrypter.setKeyPlacement(Encrypter.KeyPlacement.INLINE);

    try {
        return encrypter.encrypt(assertion);
    } catch (EncryptionException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:sunrongxin7666,项目名称:OpenSAML-ref-project-demo-v3,代码行数:21,代码来源:ArtifactResolutionServlet.java

示例3: encryptData

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
/**
 * Returns an <code>EncryptedData</code> interface. Use this operation if
 * you want to have full control over the contents of the
 * <code>EncryptedData</code> structure.
 *
 * This does not change the source document in any way.
 *
 * @param context the context <code>Document</code>.
 * @param element the <code>Element</code> that will be encrypted.
 * @param contentMode <code>true</code> to encrypt element's content only,
 *    <code>false</code> otherwise
 * @return the <code>EncryptedData</code>
 * @throws Exception
 */
public EncryptedData encryptData(
    Document context, Element element, boolean contentMode
) throws /* XMLEncryption */ Exception {
    if (log.isDebugEnabled()) {
        log.debug("Encrypting element...");
    }
    if (null == context) {
        log.error("Context document unexpectedly null...");
    }
    if (null == element) {
        log.error("Element unexpectedly null...");
    }
    if (cipherMode != ENCRYPT_MODE && log.isDebugEnabled()) {
        log.debug("XMLCipher unexpectedly not in ENCRYPT_MODE...");
    }

    if (contentMode) {
        return encryptData(context, element, EncryptionConstants.TYPE_CONTENT, null);
    } else {
        return encryptData(context, element, EncryptionConstants.TYPE_ELEMENT, null);
    }
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:37,代码来源:XMLCipher.java

示例4: newEncryptionProperties

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
/**
 * @param element
 * @return a new EncryptionProperties
 */
EncryptionProperties newEncryptionProperties(Element element) {
    EncryptionProperties result = newEncryptionProperties();

    result.setId(element.getAttributeNS(null, EncryptionConstants._ATT_ID));

    NodeList encryptionPropertyList =
        element.getElementsByTagNameNS(
            EncryptionConstants.EncryptionSpecNS, 
            EncryptionConstants._TAG_ENCRYPTIONPROPERTY);
    for (int i = 0; i < encryptionPropertyList.getLength(); i++) {
        Node n = encryptionPropertyList.item(i);
        if (null != n) {
            result.addEncryptionProperty(newEncryptionProperty((Element) n));
        }
    }

    return result;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:23,代码来源:XMLCipher.java

示例5: toElement

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
Element toElement() {
    Element result = 
        XMLUtils.createElementInEncryptionSpace(
            contextDocument, EncryptionConstants._TAG_ENCRYPTIONPROPERTY
        );
    if (null != target) {
        result.setAttributeNS(null, EncryptionConstants._ATT_TARGET, target);
    }
    if (null != id) {
        result.setAttributeNS(null, EncryptionConstants._ATT_ID, id);
    }
    // TODO: figure out the anyAttribyte stuff...
    // TODO: figure out the any stuff...

    return result;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:17,代码来源:XMLCipher.java

示例6: encryptData

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
/**
 * Returns an <code>EncryptedData</code> interface. Use this operation if
 * you want to have full control over the contents of the
 * <code>EncryptedData</code> structure.
 *
 * This does not change the source document in any way.
 *
 * @param context the context <code>Document</code>.
 * @param element the <code>Element</code> that will be encrypted.
 * @param contentMode <code>true</code> to encrypt element's content only,
 *    <code>false</code> otherwise
 * @return the <code>EncryptedData</code>
 * @throws Exception
 */
public EncryptedData encryptData(
    Document context, Element element, boolean contentMode
) throws /* XMLEncryption */ Exception {
    if (log.isDebugEnabled()) {
        log.debug("Encrypting element...");
    }
    if (null == context) {
        throw new XMLEncryptionException("empty", "Context document unexpectedly null...");
    }
    if (null == element) {
        throw new XMLEncryptionException("empty", "Element unexpectedly null...");
    }
    if (cipherMode != ENCRYPT_MODE) {
        throw new XMLEncryptionException("empty", "XMLCipher unexpectedly not in ENCRYPT_MODE...");
    }

    if (contentMode) {
        return encryptData(context, element, EncryptionConstants.TYPE_CONTENT, null);
    } else {
        return encryptData(context, element, EncryptionConstants.TYPE_ELEMENT, null);
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:37,代码来源:XMLCipher.java

示例7: newEncryptionProperties

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
/**
 * @param element
 * @return a new EncryptionProperties
 */
EncryptionProperties newEncryptionProperties(Element element) {
    EncryptionProperties result = newEncryptionProperties();

    result.setId(element.getAttributeNS(null, EncryptionConstants._ATT_ID));

    NodeList encryptionPropertyList =
        element.getElementsByTagNameNS(
            EncryptionConstants.EncryptionSpecNS,
            EncryptionConstants._TAG_ENCRYPTIONPROPERTY);
    for (int i = 0; i < encryptionPropertyList.getLength(); i++) {
        Node n = encryptionPropertyList.item(i);
        if (null != n) {
            result.addEncryptionProperty(newEncryptionProperty((Element) n));
        }
    }

    return result;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:23,代码来源:XMLCipher.java

示例8: toElement

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
/**
 * @return the XML Element form of that Reference
 */
public Element toElement() {
    String tagName = getType();
    Element result =
        ElementProxy.createElementForFamily(
            contextDocument,
            EncryptionConstants.EncryptionSpecNS,
            tagName
        );
    result.setAttributeNS(null, EncryptionConstants._ATT_URI, uri);

    // TODO: Need to martial referenceInformation
    // Figure out how to make this work..
    // <any namespace="##other" minOccurs="0" maxOccurs="unbounded"/>

    return result;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:20,代码来源:XMLCipher.java

示例9: itemEncryptedKey

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
/**
 * Method itemEncryptedKey
 *
 * @param i
 * @return the asked EncryptedKey element, null if the index is too big
 * @throws XMLSecurityException
 */
public EncryptedKey itemEncryptedKey(int i) throws XMLSecurityException {
    if (encryptedKeys != null) {
        return encryptedKeys.get(i);
    }
    Element e =
        XMLUtils.selectXencNode(
            getFirstChild(), EncryptionConstants._TAG_ENCRYPTEDKEY, i);

    if (e != null) {
        XMLCipher cipher = XMLCipher.getInstance();
        cipher.init(XMLCipher.UNWRAP_MODE, null);
        return cipher.loadEncryptedKey(e);
    }
    return null;
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:23,代码来源:KeyInfo.java

示例10: testEncryptedKeyWithRecipient

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
@org.junit.Test
public void testEncryptedKeyWithRecipient() throws Exception {
    String filename =
        "src/test/resources/org/apache/xml/security/encryption/encryptedKey.xml";
    if (basedir != null && !"".equals(basedir)) {
        filename = basedir + "/" + filename;
    }
    File f = new File(filename);

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

    XMLCipher keyCipher = XMLCipher.getInstance();
    keyCipher.init(XMLCipher.UNWRAP_MODE, null);

    NodeList ekList =
        document.getElementsByTagNameNS(
            EncryptionConstants.EncryptionSpecNS, EncryptionConstants._TAG_ENCRYPTEDKEY
        );
    for (int i = 0; i < ekList.getLength(); i++) {
        EncryptedKey ek =
            keyCipher.loadEncryptedKey(document, (Element) ekList.item(i));
        assertNotNull(ek.getRecipient());
    }
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:26,代码来源:XMLCipherTest.java

示例11: testEecryptToByteArray

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
@org.junit.Test
public void testEecryptToByteArray() throws Exception {
    if (!bcInstalled) {
        return;
    }
    KeyGenerator keygen = KeyGenerator.getInstance("AES");
    keygen.init(128);
    Key key = keygen.generateKey();

    Document document = document();

    XMLCipher cipher = XMLCipher.getInstance(XMLCipher.AES_128_GCM);
    cipher.init(XMLCipher.ENCRYPT_MODE, key);
    cipher.getEncryptedData();

    Document encrypted = cipher.doFinal(document, document);

    XMLCipher xmlCipher = XMLCipher.getInstance();
    xmlCipher.init(XMLCipher.DECRYPT_MODE, key);
    Element encryptedData = (Element) encrypted.getElementsByTagNameNS(EncryptionConstants.EncryptionSpecNS, EncryptionConstants._TAG_ENCRYPTEDDATA).item(0);

    xmlCipher.decryptToByteArray(encryptedData);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:24,代码来源:XMLCipherTest.java

示例12: findEncryptedDataElement

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
private Element findEncryptedDataElement(Element element) {
    // First check the Element itself
    if (EncryptionConstants._TAG_ENCRYPTEDDATA.equals(element.getLocalName())
        && EncryptionConstants.EncryptionSpecNS.equals(element.getNamespaceURI())) {
        return element;
    }
    
    // Now check the child nodes
    Node child = element.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element childElement = (Element)child;
            if (EncryptionConstants._TAG_ENCRYPTEDDATA.equals(childElement.getLocalName())
                && EncryptionConstants.EncryptionSpecNS.equals(childElement.getNamespaceURI())) {
                return childElement;
            }
        }
        child = child.getNextSibling();
    }
    
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:23,代码来源:XMLSecurityDataFormat.java

示例13: findEncryptedKeyMethod

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
private String findEncryptedKeyMethod(Element element) {
    Node child = element.getFirstChild();
    while (child != null) {
        if (child.getNodeType() == Node.ELEMENT_NODE) {
            Element childElement = (Element)child;
            if (Constants._TAG_KEYINFO.equals(childElement.getLocalName())
                && Constants.SignatureSpecNS.equals(childElement.getNamespaceURI())) {
                Node keyInfoChild = child.getFirstChild();
                while (keyInfoChild != null) {
                    if (child.getNodeType() == Node.ELEMENT_NODE) {
                        childElement = (Element)keyInfoChild;
                        if (EncryptionConstants._TAG_ENCRYPTEDKEY.equals(childElement.getLocalName())
                            && EncryptionConstants.EncryptionSpecNS.equals(childElement.getNamespaceURI())) {
                            return findEncryptionMethod(childElement);
                        }
                    }
                    keyInfoChild = keyInfoChild.getNextSibling();
                }
            }
        }
        child = child.getNextSibling();
    }
    
    return null;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:26,代码来源:XMLSecurityDataFormat.java

示例14: testFullPayloadAsymmetricKeyEncryptionMGF256

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
@Test
public void testFullPayloadAsymmetricKeyEncryptionMGF256() throws Exception {
    KeyStoreParameters tsParameters = new KeyStoreParameters();
    tsParameters.setPassword("password");
    tsParameters.setResource("sender.ts");

    final XMLSecurityDataFormat xmlEncDataFormat = new XMLSecurityDataFormat();
    xmlEncDataFormat.setKeyCipherAlgorithm(XMLCipher.RSA_OAEP_11);
    xmlEncDataFormat.setKeyOrTrustStoreParameters(tsParameters);
    xmlEncDataFormat.setXmlCipherAlgorithm(XMLCipher.AES_128);
    xmlEncDataFormat.setMgfAlgorithm(EncryptionConstants.MGF1_SHA256);
    xmlEncDataFormat.setRecipientKeyAlias("recipient");

    context.addRoutes(new RouteBuilder() {
        public void configure() {
            from("direct:start")
                .marshal(xmlEncDataFormat).to("mock:encrypted");
        }
    });
    xmlsecTestHelper.testEncryption(context);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:22,代码来源:XMLEncryption11Test.java

示例15: decryptElementContent

import org.apache.xml.security.utils.EncryptionConstants; //导入依赖的package包/类
/**
 * 
 * @param element
 * @return the <code>Node</code> as a result of the decrypt operation.
 * @throws XMLEncryptionException
 */
private Document decryptElementContent(Element element) throws XMLEncryptionException {
    Element e = 
        (Element) element.getElementsByTagNameNS(
            EncryptionConstants.EncryptionSpecNS,
            EncryptionConstants._TAG_ENCRYPTEDDATA
        ).item(0);

    if (null == e) {
        throw new XMLEncryptionException("No EncryptedData child element.");
    }

    return decryptElement(e);
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:20,代码来源:XMLCipher.java


注:本文中的org.apache.xml.security.utils.EncryptionConstants类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。