GeeCON Prague 2014*
The moose likes Java in General and the fly likes Error while encrypting the xml file using asymmetric cipher...pls help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "Error while encrypting the xml file using asymmetric cipher...pls help" Watch "Error while encrypting the xml file using asymmetric cipher...pls help" New topic
Author

Error while encrypting the xml file using asymmetric cipher...pls help

sachin kataria
Ranch Hand

Joined: Mar 27, 2006
Posts: 45
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: 42031
    
  64
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.


Ping & DNS - my free Android networking tools app
sachin kataria
Ranch Hand

Joined: Mar 27, 2006
Posts: 45
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: 42031
    
  64
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
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...

pascal
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18874
    
  40

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.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
sachin kataria
Ranch Hand

Joined: Mar 27, 2006
Posts: 45
now i generate keypairgenerator using RSA algo.
and for xml encryption initialize cipher using RSA algo.

and it is working successfully......

Thanks everybody for help........
 
GeeCON Prague 2014
 
subject: Error while encrypting the xml file using asymmetric cipher...pls help