• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Java Decryptor for .NET AES Encryptor

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I'm building a Java-based decryptor that's meant to pair with a .NET-based encryption module that uses AES Encryption.

I have the basic setup of my Java Encryptor working, but need to find a way to derive the key in the same manner that the .NET equivalent is doing:

Basically, I need to find an equivalent for adding salt, and performing this pseudo-random key generation, exactly as it's being done in .NET, so that a corresponding Java App could decrypt what this .NET app is encrypting.

Any help greatly appreciated.

// <C# Code>
PasswordDeriveBytes password = new PasswordDeriveBytes( m_sPasswordPhrase, SaltValueBytes, m_sHashAlgorithm, m_iIterations );
// </C# Code>

Here's the basic java code that I'm using:

// <Java Code>
import java.io.*;
import java.security.*;
import javax.crypto.*;
import javax.crypto.spec.*;

public class Bouncer {
private final String myKey = "@1B2c3D4e5F6g7H8";//"krc^agwsgmp^&qs*"; //This is the key used for Encrypting and Decrypting
private Cipher cipher = null;
private KeyGenerator kgen =null;
SecretKeySpec skeySpec = null;

/** Creates a new instance of Bouncer */
public Bouncer() {
initialize();
}

private void initialize(){
try{
//kgen = KeyGenerator.getInstance("AES");
//kgen.init(128); // 192 and 256 bits may not be available
skeySpec = new SecretKeySpec(this.myKey.getBytes(), "AES");

// Instantiate the cipher
cipher = Cipher.getInstance("AES");
}
catch(Exception e){
System.out.println("Error: AES Libraries not found. Details:");
System.out.println(e.toString());
}
}

public byte[] encryptString(String clearText){
byte[] encrypted=null;

byte[] clearTextBytes = clearText.getBytes();

try{
cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
encrypted = cipher.doFinal(clearTextBytes);

}
catch(Exception e){
System.out.println("Error occurred while performing encryption. Details:");
System.out.println(e);
}
return encrypted;
}
}

// </Java Code>

Regards,
Reuben.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic