Hello!
I am working on a problem with an existing application used to generate encrypted URLs. The application
1. URL encodes the payload
2. Generates a checksum which is prepended to the payload
3. The result is zipped using GZipOutputStream (for compression)
4. The GZipped string is then encrypted using Blowfish using SunJCE.
5. The above result is Bas64 encoded and URL encoded.
The problem that I am facing is that the program works fine as long as it is called once. But, if it is called repeatedly in a loop, some of the encrypted URLs are invalid. I noticed that the length of the result from the Gzip method varies. If it is a particular length, then the encryption works well otherwise, it gets messed up.
By the way, the payload is a fixed length string.
Here is the GZip code.
private static byte[] zipIt ( String parameterString )
{
try {
ByteArrayOutputStream catcher = new ByteArrayOutputStream();
DelayOutputStream dyos = new DelayOutputStream(catcher);
GZIPOutputStream gzipOut = new GZIPOutputStream( catcher );
byte[] bytesToZip = parameterString.getBytes();
gzipOut.write( bytesToZip, 0, bytesToZip.length );
gzipOut.close();
return catcher.toByteArray();
}
catch ( Exception ioe ) {
ioe.printStackTrace();
return "error".getBytes();
}
}
How do I ensure that the zipped string is always of the same length for the encryption to work?
Thanks in advance!
coderiyer
I am working on a problem with an existing application used to generate encrypted URLs. The application
1. URL encodes the payload
2. Generates a checksum which is prepended to the payload
3. The result is zipped using GZipOutputStream (for compression)
4. The GZipped string is then encrypted using Blowfish using SunJCE.
5. The above result is Bas64 encoded and URL encoded.
The problem that I am facing is that the program works fine as long as it is called once. But, if it is called repeatedly in a loop, some of the encrypted URLs are invalid. I noticed that the length of the result from the Gzip method varies. If it is a particular length, then the encryption works well otherwise, it gets messed up.
By the way, the payload is a fixed length string.
Here is the GZip code.
private static byte[] zipIt ( String parameterString )
{
try {
ByteArrayOutputStream catcher = new ByteArrayOutputStream();
DelayOutputStream dyos = new DelayOutputStream(catcher);
GZIPOutputStream gzipOut = new GZIPOutputStream( catcher );
byte[] bytesToZip = parameterString.getBytes();
gzipOut.write( bytesToZip, 0, bytesToZip.length );
gzipOut.close();
return catcher.toByteArray();
}
catch ( Exception ioe ) {
ioe.printStackTrace();
return "error".getBytes();
}
}
How do I ensure that the zipped string is always of the same length for the encryption to work?
Thanks in advance!
coderiyer