spetrowitsch
asked on
Looking for an encryption-/decryption-algorithm which produces short output
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.getInstan ce(
ENCRYPTION_ALGORITHM);
SecretKey pbeKey = keyFactory.generateSecret( pbeKeySpec );
pbe = Cipher.getInstance(ENCRYPT ION_ALGORI THM);
pbe.init(Cipher.ENCRYPT_MO DE, 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".getByte s());
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?
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.getInstan
ENCRYPTION_ALGORITHM);
SecretKey pbeKey = keyFactory.generateSecret(
pbe = Cipher.getInstance(ENCRYPT
pbe.init(Cipher.ENCRYPT_MO
}
catch (Exception e) {
throw new PdiRuntimeException(e);
}
ByteArrayOutputStream bufOut = new ByteArrayOutputStream();
bufOut.write("Das wird anders werden".getBytes());
CipherOutputStream encrOut = new CipherOutputStream(bufOut,
String s = new BASE64Encoder().encode( bufOut.toByteArray() );
System.out.println( s );
bufOut.reset();
bufOut.write("419".getByte
encrOut = new CipherOutputStream(bufOut,
s = new BASE64Encoder().encode( bufOut.toByteArray() );
System.out.println( s );
bufOut.reset();
bufOut.write("4198721987".
encrOut = new CipherOutputStream(bufOut,
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?
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
it is wrong,besides, the base 64 encoding will return a string.