For Programmers: Free Programming Magazines  


Home > Archive > Java Security > August 2005 > Decrypting with Cipher









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Decrypting with Cipher
gtornelas@utep.edu

2005-04-08, 3:59 am

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

2005-04-08, 4:01 pm

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/



<gtornelas@utep.edu> wrote in message
news:1112934343.746065.8600@z14g2000cwz.googlegroups.com...
> 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?
>



Ana

2005-08-09, 3:42 am

Hi all,
I also have the same problem.

Error as follows:
Exception in thread "main" javax.crypto.BadPaddingException: Data must start with zero

I tried using
Cipher.getInstance("RSA/ECB/PKCS1Padding");.
But it is showing the same error.

Thanks in advance for any suggestions.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com