Thanks, it passes! On 9/21/07, Daniele Gagliardi <[EMAIL PROTECTED]> wrote: > > ok, you're encrypting using PUBLIC key (certificate.getPublicKey ()). > It seems you have problems with java security policies. Maybe you have > to use jce unlimited strength encryption files. You can find them at > SUN java site http://java.sun.com, in the section of jdk downloads. > Choose the proper file for your version of jdk. > > > huang zhimin ha scritto: > > public void encrypt(Document document) throws Exception { > > KeyStore ks = getKeyStore(); > > X509Certificate certificate = getCertificate(ks); > > String algorithmURI = XMLCipher.AES_256; > > > > 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); > > } > > > > I have do it, but get the exception > > > > Exception was java.security.InvalidKeyException: Illegal key size or > > default parameters > > at org.apache.xml.security.encryption.XMLCipher.encryptData(Unknown > > Source) > > at org.apache.xml.security.encryption.XMLCipher.encryptData(Unknown > > Source) > > at > > org.apache.xml.security.encryption.XMLCipher.encryptElementContent > (Unknown > > Source) > > at org.apache.xml.security.encryption.XMLCipher.doFinal (Unknown > Source) > > at > > org.jtang.service.security.engine.SecurityEngine.encrypt( > SecurityEngine.java:121) > > at > > org.jtang.service.security.engine.SecurityEngineTest.testEncrypt( > SecurityEngineTest.java:141) > > > > What's wrong? > > > > On 9/21/07, *Daniele Gagliardi* <[EMAIL PROTECTED] > > <mailto:[EMAIL PROTECTED]>> wrote: > > > > If you're using asymmetric cryptography, why do you want to use > private > > key for encryption? In this way everyone who has the public key > (which > > is PUBLIC) can decrypt the xml. > > For xml encryption, you can use the very good examples in apache xml > > signature package (you can found these in > > > xml-security-1_4_1/src_samples/org/apache/xml/security/samples/encryption > > > > directory of the apache distribution in > > http://xml.apache.org/security/dist/java-library/ > > <http://xml.apache.org/security/dist/java-library/>) > > > > huang zhimin ha scritto: > > > Can anybody give me an example to encrypt xml with private key? > > > > > > -- > > > http://sourceforge.net/projects/mycodeline/ > > > http://rubyforge.org/projects/ropenwiki/ > > > > > > > > > > -- > > http://sourceforge.net/projects/mycodeline/ > > <http://sourceforge.net/projects/mycodeline/> > > http://rubyforge.org/projects/ropenwiki/ > > -- > ------------------------------------------- > Daniele Gagliardi > > Engiweb Security - Gruppo Engineering > Corso Stati Uniti 23/I > 35127 Padova, Italia > > Tel. ++39 0498692507 > Fax. ++39 0498692566 > > http://www.engiweb.com > > e-mail: [EMAIL PROTECTED] > ------------------------------------------- >
-- http://sourceforge.net/projects/mycodeline/ http://rubyforge.org/projects/ropenwiki/