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.