?
Solved

Looking for an encryption-/decryption-algorithm which produces short output

Posted on 2007-03-19
3
Medium Priority
?
316 Views
Last Modified: 2008-03-04
Hi,

I have to find a symmetric encryption-decryption algorithm, which produces short output-data. I used the following code:

                String ENCRYPTION_ALGORITHM = "PBEWithMD5AndDES";
              String pwd = "password";
              PBEParameterSpec PBE_PARAMETER_SPEC =
                  new PBEParameterSpec(new byte[] { (byte)0x01, (byte)0x23, (byte)0x45, (byte)0x67,
                   (byte)0x89, (byte)0xab, (byte)0xcd, (byte)0xef}, 1024);
              if( pwd != null ) {
                  // yes -> fetch the encryption stream
                  Cipher pbe;
                  try {
                      PBEKeySpec pbeKeySpec = new PBEKeySpec(pwd.toCharArray());
                      SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(
                              ENCRYPTION_ALGORITHM);
                      SecretKey pbeKey = keyFactory.generateSecret(pbeKeySpec);
                      pbe = Cipher.getInstance(ENCRYPTION_ALGORITHM);
                      pbe.init(Cipher.ENCRYPT_MODE, pbeKey, PBE_PARAMETER_SPEC);
                  }
                  catch (Exception e) {
                      throw new PdiRuntimeException(e);
                  }
                  ByteArrayOutputStream bufOut = new ByteArrayOutputStream();
                  bufOut.write("Das wird anders werden".getBytes());
                  CipherOutputStream encrOut =  new CipherOutputStream(bufOut, pbe);
                  String s = new BASE64Encoder().encode( bufOut.toByteArray() );
                  System.out.println( s );
                  
                  bufOut.reset();
                  bufOut.write("419".getBytes());
                  encrOut =  new CipherOutputStream(bufOut, pbe);
                  s = new BASE64Encoder().encode( bufOut.toByteArray() );
                  System.out.println( s );
                  
                  bufOut.reset();
                  bufOut.write("4198721987".getBytes());
                  encrOut =  new CipherOutputStream(bufOut, pbe);
                  s = new BASE64Encoder().encode( bufOut.toByteArray() );
                  System.out.println( s );
              }

and got - as I can see - always the next 2^n-character-length. One might say, that´s o.k., to get out of "4198721987", which is 10 characters, a return-value of 16 characters; but in fact "4198721987" is stored as an integer or long-value, so it is something like 4 characters and shouldn´t return such a long output.

Any hint, where I can find a good algorithm with less waste of bytes?
0
Comment
Question by:spetrowitsch
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Expert Comment

by:mnrz
ID: 18746746
you should not store the output as Integer.
it is wrong,besides, the base 64 encoding will return a string.
0
 

Author Comment

by:spetrowitsch
ID: 18746777
I wanted to say: The value, which I want to encrypt (and later decrypt) is in most cases an integer or long, and shouldn´t result in such long encrypted return-values.
0
 
LVL 8

Accepted Solution

by:
mnrz earned 150 total points
ID: 18746805
ok but each algorithm you use will result unexpected size of characters.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Suggested Courses
Course of the Month12 days, 15 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question