File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Security and the fly likes Need help on Cipher class for encryption Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Engineering » Security
Reply Bookmark "Need help on Cipher class for encryption" Watch "Need help on Cipher class for encryption" New topic
Author

Need help on Cipher class for encryption

Aju Joseph
Greenhorn

Joined: Feb 20, 2004
Posts: 6
Hi,

I am using javax.crypto.Cipher class for encrypting a 32 char string. I am using the "PBEWithMD5AndTripleDES" algorithm for encryption. The output of the encryption is around 50 characters. My problem is that I need to limit the number of characters in the encrypted output to 32 or less (The input string will be 32 chars, cannot be compromised). Is there a way of doing this ?

Thanks,
Aju
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35241
    
    7
I don't think there's a cipher that produces a shorter string, i.e. compresses the original string. Encryption usually adds entropy, so that the string gets longer. Have you tried other ciphers? Why can't the encrypted string be longer than the source?


Android appsImageJ pluginsJava web charts
Aju Joseph
Greenhorn

Joined: Feb 20, 2004
Posts: 6
Hi Ulf,

Thanks for the reply. It is a requirement of my application that the encrypted string needs to be 32 chars or less. Unfortunately the input string is also 32 chars. I was just hoping against hope to find a way to meet this req.

Aju
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16692
    
  19

Not sure if there are any other options, but if there are... I'm sure the crypto experts at the security forum would know.

Moving this to the security forum...

Henry
[ August 17, 2006: Message edited by: Henry Wong ]

Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 35241
    
    7
You could try a few of the other available ciphers.
Brian Mozhdehi
Ranch Hand

Joined: Aug 17, 2006
Posts: 81
You could try compressing the data first using the zip package, then encrypting the compressed data, which should shorten the resulting encrypted data.
greg stark
Ranch Hand

Joined: Aug 10, 2006
Posts: 220
You cannot use one of the PBE ciphers because they encode a salt and an iteration count along with your ciphertext. These things increase security, so you'll need to either supply them or something equivalent out-of-band, set them to constants, or live the dangerous life without them.

That said, you can still build your own version of a PBE-based cipher. If your plaintext is always 32 bytes, you can use any supported block cipher including AES. You'll need to supply an initialization vector to Cipher.init(), but you can derive the IV along with the key from the password. Details on how to do this correctly are contained in PKCS#5, http://www.rfc-editor.org/cgi-bin/rfcdoctype.pl?loc=RFC&letsgo=2898&type=http&file_format=txt.


Nice to meet you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need help on Cipher class for encryption
 
Similar Threads
File encryption / decryption retaining line feeds
Shift Operators
Encryption in Java
Need help with arrays
Generating an encrypted Key which will be around 32 characters