Encryption 使用xmlCipher.doFinal()解密SAML响应时,未获得解密密码数据的预期结果 公共静态无效解密元素(元素encryptedDataElement,PrivateKey inputKey){ 试一试{ Init.Init(); xmlchipher xmlchipher=xmlchipher.getInstance(); init(xmlchipher.DECRYPT_模式,inputKey); NodeList KeyInfoInCDATA=encryptedDataElement.GetElementsByTagnames(Constants.NS_DS,“KeyInfo”); System.out.println(“keyinfoinencata”+keyinfoinencata.item(0.getNodeName()); 如果(KeyInfoInCDATA.getLength()==0){ 抛出新的ValidationError(“EncryptedData元素内无KeyInfo”,ValidationError.KeyInfo未在加密数据中找到); } NodeList childs=keyinfoinencata.item(0.getChildNodes(); for(int i=0;i
以上代码为参考 我的回答是有密码值。需要解密密码值以获取邮件ID 我有加密的数据元素。我正在将加密的数据元素传递给Encryption 使用xmlCipher.doFinal()解密SAML响应时,未获得解密密码数据的预期结果 公共静态无效解密元素(元素encryptedDataElement,PrivateKey inputKey){ 试一试{ Init.Init(); xmlchipher xmlchipher=xmlchipher.getInstance(); init(xmlchipher.DECRYPT_模式,inputKey); NodeList KeyInfoInCDATA=encryptedDataElement.GetElementsByTagnames(Constants.NS_DS,“KeyInfo”); System.out.println(“keyinfoinencata”+keyinfoinencata.item(0.getNodeName()); 如果(KeyInfoInCDATA.getLength()==0){ 抛出新的ValidationError(“EncryptedData元素内无KeyInfo”,ValidationError.KeyInfo未在加密数据中找到); } NodeList childs=keyinfoinencata.item(0.getChildNodes(); for(int i=0;i,encryption,onelogin,Encryption,Onelogin,以上代码为参考 我的回答是有密码值。需要解密密码值以获取邮件ID 我有加密的数据元素。我正在将加密的数据元素传递给DecryptedElement(encryptedDataElement)和我的私有RSA密钥方法。 Do final未按预期工作。未获取任何日志 请检查并帮助我获取解密数据。访问正在进行解密的元素后。 我给元素encryptedData=(元素)EncryptedNodes.item(0)取而代之 加密工作正常 public static void decryptElement(
DecryptedElement(encryptedDataElement)
和我的私有RSA密钥
方法。
Do final未按预期工作。未获取任何日志
请检查并帮助我获取解密数据。访问正在进行解密的元素后。 我给元素encryptedData=(元素)EncryptedNodes.item(0)取而代之 加密工作正常
public static void decryptElement(Element encryptedDataElement, PrivateKey inputKey) {
try {
Init.init();
XMLCipher xmlCipher = XMLCipher.getInstance();
xmlCipher.init(XMLCipher.DECRYPT_MODE, inputKey);
NodeList keyInfoInEncData = encryptedDataElement.getElementsByTagNameNS(Constants.NS_DS, "KeyInfo");
System.out.println("keyInfoInEncData"+keyInfoInEncData.item(0).getNodeName());
if (keyInfoInEncData.getLength() == 0) {
throw new ValidationError("No KeyInfo inside EncryptedData element", ValidationError.KEYINFO_NOT_FOUND_IN_ENCRYPTED_DATA);
}
NodeList childs = keyInfoInEncData.item(0).getChildNodes();
for (int i=0; i < childs.getLength(); i++) {
if (childs.item(i).getLocalName() != null && childs.item(i).getLocalName().equals("RetrievalMethod")) {
Element retrievalMethodElem = (Element)childs.item(i);
if (!retrievalMethodElem.getAttribute("Type").equals("http://www.w3.org/2001/04/xmlenc#EncryptedKey")) {
throw new ValidationError("Unsupported Retrieval Method found", ValidationError.UNSUPPORTED_RETRIEVAL_METHOD);
}
String uri = retrievalMethodElem.getAttribute("URI").substring(1);
System.out.println("URI"+uri);
NodeList encryptedKeyNodes = ((Element) encryptedDataElement.getParentNode()).getElementsByTagNameNS(Constants.NS_XENC, "EncryptedKey");
for (int j=0; j < encryptedKeyNodes.getLength(); j++) {
if (((Element)encryptedKeyNodes.item(j)).getAttribute("Id").equals(uri)) {
keyInfoInEncData.item(0).replaceChild(encryptedKeyNodes.item(j), childs.item(i));
}
}
}
}
NodeList node=encryptedDataElement.getChildNodes().item(2).getChildNodes();
xmlCipher.setKEK(inputKey);
xmlCipher.**doFinal**(encryptedDataElement.getOwnerDocument(), encryptedDataElement, false);
} catch (Exception e) {
LOGGER.warn("Error executing decryption: " + e.getMessage(), e);
}
}