public void encrypt(Document document) throws Exception { KeyStore ks = getKeyStore(); X509Certificate certificate = getCertificate(ks); String algorithmURI = XMLCipher.SHA256;
Element rootElement = document.getDocumentElement(); XMLCipher xmlCipher = XMLCipher.getInstance(algorithmURI); xmlCipher.init(XMLCipher.ENCRYPT_MODE, certificate.getPublicKey()); EncryptedData encryptedData = xmlCipher.getEncryptedData(); KeyInfo keyInfo = new KeyInfo(document); encryptedData.setKeyInfo(keyInfo); xmlCipher.doFinal(document, rootElement, true); } The keystore is provided from the example of xml-security. The exception is Original Exception was java.security.NoSuchAlgorithmException: Cannot find any provider supporting SHA-256 at org.apache.xml.security.encryption.XMLCipher.getInstance(Unknown Source) at org.jtang.service.security.engine.SecurityEngine.encrypt( SecurityEngine.java:117) I don't know how to solve it. -- http://sourceforge.net/projects/mycodeline/ http://rubyforge.org/projects/ropenwiki/