Hyejung,

Oops. I missed this - apologies!

Did you get this working? My first thought would be that you are trying to create a key using

SecretKeySpec ks = new
    SecretKeySpec(encryptionKeyCipherValue.getValue().getBytes(),
                  ek.getEncryptionMethod().getAlgorithm());

Which will fail, as the bytes you are using are encrypted bytes from the doc, and the algorithm is an xml-encryption algorithm, not a JCE algorithm.

If you are still having problems, come back to the list and we will see what we can do.

Cheers,
        Berin


Hye-Jung Kim wrote:


Hello,
I am trying to decrypt the encrypted xml data using KeyInfo.
I extracted CipherValue of KeyInfo which is kek(key encryption key) to pass on to my XmlCipher however, I am getting the exception java.security.NoSuchAlgorithmException: Algorithm http://www.w3.org/2001/04/xmlenc#kw-tripledes not available. I've tried different provider but still failed to retrieve kek value from KeyInfo. I am not sure what I am doing wrong to retrieve kek value in order to decrypt xml data from KeyInfo ?


Thanks in advance.

hyejung

========== my java code =====================

Key key = null;
Element e = (Element) encryptedDoc.getElementsByTagNameNS(EncryptionConstants.EncryptionSpecNS,
EncryptionConstants._TAG_ENCRYPTEDDATA).item(0); cipher = XMLCipher.getInstance();
cipher.init(XMLCipher.DECRYPT_MODE, null);
EncryptedData encryptedData = cipher.loadEncryptedData(encryptedDoc, e);
if(encryptedData == null) {
throw new Exception("EncryptedData is null");
}else if (encryptedData.getKeyInfo() == null) {
throw new Exception("KeyInfo of the EncryptedData is null");
}
EncryptedKey ek = encryptedData.getKeyInfo().itemEncryptedKey(0);
*if (ek != null) {
CipherValue encryptionKeyCipherValue = ek.getCipherData().getCipherValue();
SecretKeySpec ks = new SecretKeySpec(encryptionKeyCipherValue.getValue().getBytes(),ek.getEncryptionMethod().getAlgorithm()); Key kek = keyFactory.generateSecret(ks);
XMLCipher keyCipher = XMLCipher.getInstance();
keyCipher.init(XMLCipher.UNWRAP_MODE, kek);
key = keyCipher.decryptKey(ek, encryptedData.getEncryptionMethod().getAlgorithm());
}
* //initialize the XMLCipher
XMLCipher cipher3 = XMLCipher.getInstance();
cipher3.init(XMLCipher.DECRYPT_MODE, key);
Document decryptedDoc = cipher.doFinal(encryptedDoc, e);
XMLUtils.outputDOM(decryptedDoc, output); ====== my encrypted xml data ===============
<xenc:EncryptedData Type="*http://www.w3.org/2001/04/xmlenc#Element*"; xmlns:xenc="*http://www.w3.org/2001/04/xmlenc#*";>
* * <xenc:EncryptionMethod Algorithm="*http://www.w3.org/2001/04/xmlenc#tripledes-cbc*"; xmlns:xenc="*http://www.w3.org/2001/04/xmlenc#*"; />
*-* <file:///W:/Rhapsody/XMLSecurityFilter/resources/processed/encryptedWithKeyInfo.xml#> <ds:KeyInfo xmlns:ds="*http://www.w3.org/2000/09/xmldsig#*";>
*-* <file:///W:/Rhapsody/XMLSecurityFilter/resources/processed/encryptedWithKeyInfo.xml#> <xenc:EncryptedKey xmlns:xenc="*http://www.w3.org/2001/04/xmlenc#*";>
* * <xenc:EncryptionMethod Algorithm="*http://www.w3.org/2001/04/xmlenc#kw-tripledes*"; xmlns:xenc="*http://www.w3.org/2001/04/xmlenc#*"; />
*-* <file:///W:/Rhapsody/XMLSecurityFilter/resources/processed/encryptedWithKeyInfo.xml#> <xenc:CipherData xmlns:xenc="*http://www.w3.org/2001/04/xmlenc#*";>
* * <xenc:CipherValue xmlns:xenc="*http://www.w3.org/2001/04/xmlenc#*";>*LYhDusdc65NgbAxiX1uxp7elPwp4s9qQb6dtXu1uFE6p/Wm3+/fiNQ==*</xenc:CipherValue>


* * </xenc:CipherData>
* * </xenc:EncryptedKey>
* * </ds:KeyInfo>
*-* <file:///W:/Rhapsody/XMLSecurityFilter/resources/processed/encryptedWithKeyInfo.xml#> <xenc:CipherData xmlns:xenc="*http://www.w3.org/2001/04/xmlenc#*";>
* * <xenc:CipherValue xmlns:xenc="*http://www.w3.org/2001/04/xmlenc#*";>*TxuXWSIU/xR8OEhVQt1GxIC/9ItnLWhC1/58eC8p3wPHRoKrO3vYn7LMlCLheprq*</xenc:CipherValue>


* * </xenc:CipherData>
* * </xenc:EncryptedData>

Reply via email to