Error while encrypting the xml file using asymmetric cipher...pls help
sachin kataria
Ranch Hand
Joined: Mar 27, 2006
Posts: 43
posted
0
i have to encrypt the xml file using asymmetric cyper....
in one class , i am generating private key and public key using "RSA" algorithm..using 1024 byte initialization... it is generating properly...
and after that in second class i am encrypting the xml file using "DESede" algorithm and i am using public key of above class.. but i am getting exceptione :
java.security.InvalidKeyException: Invalid key length: 162 bytes at com.sun.crypto.provider.DESedeCipher.engineGetKeySize(DashoA6275) at javax.crypto.Cipher.init(DashoA6275) at XmlEncryption.getEncryptedData(XmlEncryption.java:147) at XmlEncryption.encryptCompleteXmlFile(XmlEncryption.java:123) at demoXmlEncApp.simulateBookSellersEnd(demoXmlEncApp.java:72) at demoXmlEncApp.main(demoXmlEncApp.java:29)
so, what is that ?
i want to use RSA algo for key generatiion and DESede for cipher initialization .
is there any site for where source code of xml file encryption using asymmetric cipher is available?
pls, help me.....
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
I'm confused - are you trying to use an RSA key with a DES cipher? That wouldn't work. A full example of using JCE can be found here. It doesn't really matter whether you are encrypting XML or some other data.
i have to encrypt and decrypt the xml file... so, first i generate public and private key using RSA algo. after that for xml file encryption, i initialize cipher with DESeds algo.. that is giving me exception..
and i think the code which is in link ("found here") wont work for xml file encryption, it is use for simple data encryption
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35241
7
posted
0
Sachin, re-read and reconsider my first post: Using an RSA key with a DES cipher won't work (which is why you're getting the exception).
And for encryption it doesn't matter whether you're encrypting XML data or some other text. So I don't understand where you see a difference between "xml file encryption" and "simple data encryption" - they are the same. If you think otherwise, explain to us how you got to that opinion, and we'll try to get you going again.
pascal betz
Ranch Hand
Joined: Jun 19, 2001
Posts: 547
posted
0
what is the difference between "simple data" and "xml" its just bytes. and the Cipher just does not care where the bytes are comming from...
Originally posted by sachin kataria: i have to encrypt and decrypt the xml file... so, first i generate public and private key using RSA algo. after that for xml file encryption, i initialize cipher with DESeds algo.. that is giving me exception..
and i think the code which is in link ("found here") wont work for xml file encryption, it is use for simple data encryption
To use a triple DES cipher (DESede), you need a triple DES secret key. To use a RSA cipher, you need a RSA public and/or private key.
These are two different algorithms, you can't generate a key for one and use it in the other. Not only don't I think the keys are the same size, there may also be safety checks to prevent you from accidentally doing so.