Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
sachin kataria
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
sachin kataria
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Marshal
Pie
Posts: 21114
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
sachin kataria
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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........
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic