-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
5.0
-
x86
-
linux
FULL PRODUCT VERSION :
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux hazlo.hazlorealidad.com 2.6.9-1.667smp #1 SMP Tue Nov 2 14:59:52 EST 2004 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
If the public key is used to encrypt data and then the same public key is used to decrypt the data then the Cipher input stream produces no data, or if another key is used to try to decypt the data. the same thing happens
I believe that it should detect that there was a problem decrypting the data and throw an exception, or the documentation should be modified to reflect this.
Reason:
The return code from the read -1 signifies end of file NOT there was a problem reading or in this case decrypting the data, maybe IOException would be appropriate or a subclass of IOException
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see test case
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An Exception
ACTUAL -
wrote 128
Read -1
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
KeyPairGenerator generator=KeyPairGenerator.getInstance("RSA");
KeyPair pair=generator.generateKeyPair();
PrivateKey privateKey=pair.getPrivate();
PublicKey publicKey=pair.getPublic();
Cipher c = Cipher.getInstance("RSA");
c.init(Cipher.PUBLIC_KEY,publicKey);
//c.init(Cipher.PRIVATE_KEY,privateKey);
ByteArrayOutputStream bout=new ByteArrayOutputStream();
PrintStream out=new PrintStream(new CipherOutputStream(
bout,c));
out.println("Hello");
out.close();
byte[] bytes=bout.toByteArray();
System.out.println("wrote "+bytes.length);
ByteArrayInputStream bin=new ByteArrayInputStream(bytes);
c = Cipher.getInstance("RSA");
c.init(Cipher.PUBLIC_KEY,publicKey);
//c.init(Cipher.PRIVATE_KEY,privateKey);
byte []buffer=new byte[4096];
InputStream in=new CipherInputStream(bin,c);
int nbytes=in.read(buffer);
System.out.println("Read "+nbytes);
if (nbytes>0) System.out.write(buffer,0,nbytes);
in.close();
---------- END SOURCE ----------
###@###.### 2005-04-29 09:39:06 GMT
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode, sharing)
ADDITIONAL OS VERSION INFORMATION :
Linux hazlo.hazlorealidad.com 2.6.9-1.667smp #1 SMP Tue Nov 2 14:59:52 EST 2004 i686 i686 i386 GNU/Linux
A DESCRIPTION OF THE PROBLEM :
If the public key is used to encrypt data and then the same public key is used to decrypt the data then the Cipher input stream produces no data, or if another key is used to try to decypt the data. the same thing happens
I believe that it should detect that there was a problem decrypting the data and throw an exception, or the documentation should be modified to reflect this.
Reason:
The return code from the read -1 signifies end of file NOT there was a problem reading or in this case decrypting the data, maybe IOException would be appropriate or a subclass of IOException
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
see test case
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
An Exception
ACTUAL -
wrote 128
Read -1
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
KeyPairGenerator generator=KeyPairGenerator.getInstance("RSA");
KeyPair pair=generator.generateKeyPair();
PrivateKey privateKey=pair.getPrivate();
PublicKey publicKey=pair.getPublic();
Cipher c = Cipher.getInstance("RSA");
c.init(Cipher.PUBLIC_KEY,publicKey);
//c.init(Cipher.PRIVATE_KEY,privateKey);
ByteArrayOutputStream bout=new ByteArrayOutputStream();
PrintStream out=new PrintStream(new CipherOutputStream(
bout,c));
out.println("Hello");
out.close();
byte[] bytes=bout.toByteArray();
System.out.println("wrote "+bytes.length);
ByteArrayInputStream bin=new ByteArrayInputStream(bytes);
c = Cipher.getInstance("RSA");
c.init(Cipher.PUBLIC_KEY,publicKey);
//c.init(Cipher.PRIVATE_KEY,privateKey);
byte []buffer=new byte[4096];
InputStream in=new CipherInputStream(bin,c);
int nbytes=in.read(buffer);
System.out.println("Read "+nbytes);
if (nbytes>0) System.out.write(buffer,0,nbytes);
in.close();
---------- END SOURCE ----------
###@###.### 2005-04-29 09:39:06 GMT