Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Security / April 2005

Tip: Looking for answers? Try searching our database.

Decrypting with Cipher

Thread view: 
gtornelas@utep.edu - 08 Apr 2005 05:25 GMT
Hi

I have a client that encrypts a message and sends it to the server.  I
can encrypt fine:
            byte[] dataToSend = new byte[somelength];

            /*fill dataToSend with some data*/

            Cipher cipher = Cipher.getInstance("RSA");
        cipher.init(Cipher.ENCRYPT_MODE,  serverPubKey);             byte[]
ciphertext = cipher.doFinal(dataToSend);

However, when I try to decrypt on the server side with:

        Cipher cipher = Cipher.getInstance("RSA");
    cipher.init(Cipher.DECRYPT_MODE,  serverPrivateKey);
    byte[] dataReceived = cipher.doFinal(data);

The output alternates (most of the time is 1 but some times is 2)
between follong errors:

         1.  javax.crypto.BadPaddingException:  Data must start with
zero
         2.  javax.crypto.BadPaddingException:  Message is larger than
modulus.

Does anyone have any idea how I can fix this?
Karl Scheibelhofer - 08 Apr 2005 16:00 GMT
try

Cipher.getInstance("RSA/ECB/PKCS1Padding");

on both sides.

 Karl

--

Karl Scheibelhofer, IAIK - Graz University of Technology
Inffeldgasse 16a, 8010 Graz, Austria
Fax: +43 316 873 5520
http://jce.iaik.tugraz.at/

> Hi
>
[quoted text clipped - 23 lines]
>
> Does anyone have any idea how I can fix this?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.