Hi guys,
I have this code for creating secret key and decrypting which is in JAVA and is running ok. I would like to implement it in the Robot so that I can generate report. Kindly assist, anyone with ideas on how to convert it to VB.NET
import org.apache.commons.codec.binary.Base64;
import java.security.Key;
import javax.crypto.Cipher;
import java.io.UnsupportedEncodingException;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.security.MessageDigest;
import javax.crypto.spec.SecretKeySpec;
public class AESEncryptor
{
private static SecretKeySpec secretKey;
private static byte[] key;
private static String key1;
public static void setKey(final String myKey, final int iterations) {
AESEncryptor.key1 = myKey.toString();
MessageDigest sha = null;
try {
AESEncryptor.key = myKey.getBytes("UTF-8");
sha = MessageDigest.getInstance("SHA-256");
for (int i = 1; i <= iterations; ++i) {
AESEncryptor.key = sha.digest(AESEncryptor.key);
}
AESEncryptor.key = Arrays.copyOf(AESEncryptor.key, 16);
AESEncryptor.secretKey = new SecretKeySpec(AESEncryptor.key, "AES");
}
catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch (UnsupportedEncodingException e2) {
e2.printStackTrace();
}
}
public static byte[] decrypt(final byte[] strToDecrypt) {
try {
final Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5PADDING");
cipher.init(2, AESEncryptor.secretKey);
return cipher.doFinal(strToDecrypt);
}
catch (Exception e) {
System.out.println("Error while decrypting: " + e.toString());
return null;
}
}
}
I would like to call the them by:
public static void main(String args){
byte[] df = null;
final byte[] decryptedData = "myEncryptedData";
try {
AESEncryptor.setKey("mysecretCode", 10);
df = AESEncryptor.decrypt(decryptedData);
}
catch (Exception e) {
e.printStackTrace();
}
}
Thanks in advance: @Yoichi