Hi :) I'm hoping this is the right list to be emailing this question to. I'm using a home-made XML Encryption implementation which uses javax.crypto.* classes but unfortunately I'm not the developer of this implementation. In order to test interoperability of it with well-known API, I'm trying to encrypt a XML document with XML Security and decrypt the result with my implementation, and vice-versa. I don't known how to do this and I feel a lilltle bit lost with all the initialization and configuration paramters of XML Security. Could someone teach me how to do ? Here are XML Security encryption : ======== KeyGenerator keyGenerator = KeyGenerator.getInstance("DESede", "BC"); keyGenerator.init(secureRandom); SecretKey sessionKey = keyGenerator.generateKey();
XMLCipher xmlCipherRSA = XMLCipher.getProviderInstance(XMLCipher.RSA_v1dot5, "BC"); xmlCipherRSA.init(XMLCipher.WRAP_MODE, clefPublique); EncryptedKey encryptedKey = xmlCipherRSA.encryptKey(doc, sessionKey); Element rootElement = doc.getDocumentElement(); XMLCipher xmlCipher = XMLCipher.getProviderInstance(TRIPLEDES, "BC"); xmlCipher.init(XMLCipher.ENCRYPT_MODE, sessionKey); EncryptedData encryptedData = xmlCipher.getEncryptedData(); KeyInfo keyInfo = encryptedData.getKeyInfo(); if (keyInfo == null) { keyInfo = new KeyInfo(doc); encryptedData.setKeyInfo(keyInfo); } keyInfo.add(encryptedKey); xmlCipher.doFinal(doc, rootElement, true); ======== Here are home-made encryption : ======== KeyGenerator keyGen; keyGen = KeyGenerator.getInstance("DESede", "BC"); keyGen.init(secureRandom); SecretKey key = keyGen.generateKey(); Cipher cipherRSA = Cipher.getInstance("RSA/NONE/PKCS1PADDING", "BC"); cipherRSA.init(Cipher.ENCRYPT_MODE, this.publicKey); byte[] encryptedKey = cipherRSA.doFinal(key.getEncoded()); String sessionKey = new String(Base64.encodeBase64(encryptedKey, false)); byte[] iv = { (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 }; Cipher cipher = Cipher.getInstance("DESede/CBC/ISO10126-2Padding", "BC"); cipher.init(Cipher.ENCRYPT_MODE, key, new IvParameterSpec(iv)); byte[] encryptedBytes = cipher.doFinal(data.substring(begin + 1, end).getBytes("UTF-8")); byte[] ivBytes = concatanate(iv, encryptedBytes); String cipherValue = new String(Base64.encodeBase64(ivBytes)); ======== Thanks in advance for all Ticker