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


Java XMLCipher.loadEncryptedData方法代码示例

本文整理汇总了Java中org.apache.xml.security.encryption.XMLCipher.loadEncryptedData方法的典型用法代码示例。如果您正苦于以下问题:Java XMLCipher.loadEncryptedData方法的具体用法?Java XMLCipher.loadEncryptedData怎么用?Java XMLCipher.loadEncryptedData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.xml.security.encryption.XMLCipher的用法示例。


在下文中一共展示了XMLCipher.loadEncryptedData方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decryptElement

import org.apache.xml.security.encryption.XMLCipher; //导入方法依赖的package包/类
/**
 * Method decryptElement
 *
 * Take a key, encryption type and a document, find an encrypted element
 * decrypt it and return the resulting document
 *
 * @param filename File to decrypt from
 * @param key The Key to use for decryption
 */
private Document decryptElement(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);
    KeyInfo kiek = encryptedKey.getKeyInfo();
    X509Data certData = kiek.itemX509Data(0);
    XMLX509Certificate xcert = certData.itemCertificate(0);
    X509Certificate cert = xcert.getX509Certificate();
    assertTrue(rsaCert.equals(cert));

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

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

示例2: decryptUsingDOM

import org.apache.xml.security.encryption.XMLCipher; //导入方法依赖的package包/类
private Document decryptUsingDOM(
    Document document,
    Key keyWrappingKey
) throws Exception {
    NodeList nodeList =
        document.getElementsByTagNameNS(
            XMLSecurityConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
            XMLSecurityConstants.TAG_xenc_EncryptedData.getLocalPart()
        );
    Element ee = (Element)nodeList.item(0);

    // Need to pre-load the Encrypted Data so we can get the key info
    XMLCipher cipher = XMLCipher.getInstance();
    cipher.init(XMLCipher.DECRYPT_MODE, null);
    EncryptedData encryptedData = cipher.loadEncryptedData(document, ee);

    XMLCipher kwCipher = XMLCipher.getInstance();
    kwCipher.init(XMLCipher.UNWRAP_MODE, keyWrappingKey);
    KeyInfo ki = encryptedData.getKeyInfo();
    EncryptedKey encryptedKey = ki.itemEncryptedKey(0);
    Key symmetricKey =
        kwCipher.decryptKey(
            encryptedKey, encryptedData.getEncryptionMethod().getAlgorithm()
        );

    cipher.init(XMLCipher.DECRYPT_MODE, symmetricKey);
    return cipher.doFinal(document, ee);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:29,代码来源:KeyWrapEncryptionCreationTest.java

示例3: decryptElement

import org.apache.xml.security.encryption.XMLCipher; //导入方法依赖的package包/类
/**
 * Method decryptElement
 *
 * Take a key, encryption type and a file, find an encrypted element
 * decrypt it and return the resulting document
 *
 * @param filename File to decrypt from
 */
private Document decryptElement(String filename) throws Exception {
    XMLCipher cipher;

    // Parse the document in question

    String basedir = System.getProperty("basedir");
    if (basedir != null && !"".equals(basedir)) {
        filename = basedir + "/" + filename;
    }
    File f = new File(filename);

    DocumentBuilder db = XMLUtils.createDocumentBuilder(false);
    Document doc = db.parse(new java.io.FileInputStream(f));

    // Now we have the document, lets build the XMLCipher element
    Element ee = null;

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

    // Need to pre-load the Encrypted Data so we can get the key info
    ee = (Element) doc.getElementsByTagName("EncryptedData").item(0);
    cipher.init(XMLCipher.DECRYPT_MODE, null);
    EncryptedData encryptedData = cipher.loadEncryptedData(doc, ee);

    Key key = findKey(encryptedData);
    cipher.init(XMLCipher.DECRYPT_MODE, key);
    Document dd = cipher.doFinal(doc, ee);

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

示例4: decryptData

import org.apache.xml.security.encryption.XMLCipher; //导入方法依赖的package包/类
/**
 * Method decryptData
 *
 * Take a file, find an encrypted element decrypt it and return the
 * resulting byte array
 *
 * @param filename File to decrypt from
 */
private byte[] decryptData(String filename) throws Exception {

    XMLCipher cipher;

    // Parse the document in question
    String basedir = System.getProperty("basedir");
    if (basedir != null && !"".equals(basedir)) {
        filename = basedir + "/" + filename;
    }
    File f = new File(filename);

    DocumentBuilder db = XMLUtils.createDocumentBuilder(false);
    Document doc = db.parse(new java.io.FileInputStream(f));

    // Now we have the document, lets build the XMLCipher element
    Element ee = null;

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

    // Need to pre-load the Encrypted Data so we can get the key info
    ee = (Element) doc.getElementsByTagName("EncryptedData").item(0);
    cipher.init(XMLCipher.DECRYPT_MODE, null);
    EncryptedData encryptedData = cipher.loadEncryptedData(doc, ee);

    Key key = findKey(encryptedData);
    cipher.init(XMLCipher.DECRYPT_MODE, key);

    return cipher.decryptToByteArray(ee);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:39,代码来源:BaltimoreEncTest.java

示例5: decrypt

import org.apache.xml.security.encryption.XMLCipher; //导入方法依赖的package包/类
private Document decrypt(
    Document document,
    Key keyWrappingKey
) throws Exception {
    NodeList nodeList = document.getElementsByTagNameNS(
            XMLSecurityConstants.TAG_xenc_EncryptedData.getNamespaceURI(),
            XMLSecurityConstants.TAG_xenc_EncryptedData.getLocalPart()
        );
    Element ee = (Element)nodeList.item(0);

    // Need to pre-load the Encrypted Data so we can get the key info
    XMLCipher cipher = XMLCipher.getInstance();
    cipher.init(XMLCipher.DECRYPT_MODE, null);
    EncryptedData encryptedData = cipher.loadEncryptedData(document, ee);

    XMLCipher kwCipher = XMLCipher.getInstance();
    kwCipher.init(XMLCipher.UNWRAP_MODE, keyWrappingKey);
    KeyInfo ki = encryptedData.getKeyInfo();
    EncryptedKey encryptedKey = ki.itemEncryptedKey(0);
    Key symmetricKey =
        kwCipher.decryptKey(
            encryptedKey, encryptedData.getEncryptionMethod().getAlgorithm()
        );

    cipher.init(XMLCipher.DECRYPT_MODE, symmetricKey);
    return cipher.doFinal(document, ee);
}
 
开发者ID:Legostaev,项目名称:xmlsec-gost,代码行数:28,代码来源:KeyWrapEncryptionAlgorithmTest.java

示例6: decryptElementDOM

import org.apache.xml.security.encryption.XMLCipher; //导入方法依赖的package包/类
/**
 * Decrypt using DOM API
 */
private Document decryptElementDOM(Document doc, Key rsaKey) 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);

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


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