I am not sure how to use SHA-256 as a cipher algorithm, and doubt you would use a public key from a certificate with it. Also, since you seem to be encrypting a significant amount of data I'd suggest you generate a symmetric key (TRIPLEDES or AES), encrypt the data ("rootElement") with it, and then encrypt the symmetric key with the public key from the certificate (via RSA_v1dot5 or RSA_OAEP
Good Luck, Mike "huang zhimin" <[EMAIL PROTECTED]> wrote on 09/22/2007 04:49:18 AM: > 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/