• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Encryption with Blowfish OS compatibility ?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am creating an encrypted license file with Java on a Linux machine. On the same linux machine I can use another program which has the same pass phrase to decrpyt this file. It works well.

If I copy that file onto a windows machine and run the same program, I get a BadPaddingException :



If I create the file on the windows machine, then I can decrypt it on the Windows machine. So it works well enough. Does anybody know whats going on here ? I am moving this app into production soon and I would like a better understanding of whats going on so I can deal with problems that might crop up.

Encryptino code :





Thanks in avance

Spunog
 
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would bet your problem is that you are using the no-args String.getBytes() method. This is almost always incorrect but it uses the platform's default charset. This default may be different on different platforms. By using the default charset you are risking nonportable behavior.

Always specify an explicit charset. In almost all cases you should always specify the "UTF-8" charset.
 
Spun Og
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Greg,

Many thanks for your response.

I read my file as follows :


SecretKeySpec key = new SecretKeySpec(new String("mypassword").getBytes(), "Blowfish");
// Read the encrypted data
FileInputStream fis = new FileInputStream(logType);
byte[] buffer = new byte[(int)new File("data").length()];

byte[] temp = new byte[new Long( DATA_FILE.length()).intValue()];
int bytesRead = fis.read(temp);
byte[] data = new byte[bytesRead];
System.arraycopy(temp, 0, data, 0, bytesRead);

// Create the cipher for encrypting
Cipher cipher = Cipher.getInstance(CompetencyService.TOKEN);
cipher.init(Cipher.DECRYPT_MODE, key);

// Decrypt the data
byte[] decrypted = cipher.doFinal(data);
String[] params = convertByteArrayToString(decrypted).split(System.getProperty("line.separator"));



The only time I use the String.readBytes() is on the passkey. Is this what you mean ?

Thanks

Spunog
 
greg stark
Ranch Hand
Posts: 220
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you serious? All you have to do is read what I wrote and read the code you posted.
 
Paper jam tastes about as you would expect. Try some on this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic