Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

AES encrypt then decrypt getting strange characters

843811Dec 27 2005 — edited Dec 27 2005
Hi, i'm trying to perform a simple encrypt and decrypt process using AES in JCE. i'd installed the 'Unlimited Strength' package for security in java, and am using JDK version 1.4.2_10. A few problems occur :

1) When i'm using 128 bit as raw bytes for the key, i only can encrypt and decrypt for up to 64 bytes of data, is it true that AES runs that way? what if i got a whole paragraph of characters that i need to encrypt? When i try to decrypt a block of bytes larget than 64 bytes i get funny characters.

2) when i'm trying to encrypt and decrypt numbers with static raw bytes as key, i.e. 123456, there would be a time when the decryption gives me nothing. It only happens when a particular key is used and the number is placed in a particular space. e.g. when i use the string 'testing123456789' to get the raw bytes and contruct the key, later on and try to encrypt and decrypt the string 'wwwwwww0034567, i find that the CipherOutputStream return nothing.

Here's some part of my codings:
//getting the secret key spec
String keyString = "testing123456789";
byte[] keyb = keyString.getBytes();
SecretKeySpec key = new SecretKeySpec(keyb, transformation);
//......
//to decrypt the stream of bytes. in and out are inputstreams and 
//outputstreams
cipher.init(Cipher.DECRYPT_MODE, key);
// Bytes read from in will be decrypted
in = new CipherInputStream(in, cipher);
// Read in the input bytes and write to out 
int numRead = 0;
while ((numRead = in.read(buf)) >= 0) {  
   out.write(buf, 0, numRead);
}
in.close();
out.flush();
out.close();
i'm quite new in cryptography, so if there's any comments or suggestions please do remind me.

Thanx in advance for the help
fLy
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 24 2006
Added on Dec 27 2005
1 comment
655 views