I need the below Code of java Script to be Converted to a DLL to be linked to a Vb.Net Application Can Some One Help me.
package sage300;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.crypto.Cipher;
import javax.crypto.CipherInputStream;
import javax.crypto.CipherOutputStream;
import javax.crypto.SecretKey;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.DESKeySpec;
public class EncryptTTUM {
public static void main(String[] args) {
try {
String key = "balaji23"; // needs to be at least 8 characters for DES
if(args.length == 1)
{
String fileName = args[0];
System.out.println("Encrypting "+fileName);
String encFileName = args[0]+".enc";
FileInputStream fis = new FileInputStream(fileName);
FileOutputStream fos = new FileOutputStream(encFileName);
encrypt(key, fis, fos);
System.out.println("Encrypted File Name "+encFileName);
}
else
{
System.out.println("Invalid no of Command Line Arguments");
}
} catch (Throwable e) {
e.printStackTrace();
}
}
public static void encrypt(String key, InputStream is, OutputStream os) throws Throwable {
encryptOrDecrypt(key, Cipher.ENCRYPT_MODE, is, os);
}
public static void decrypt(String key, InputStream is, OutputStream os) throws Throwable {
encryptOrDecrypt(key, Cipher.DECRYPT_MODE, is, os);
}
public static void encryptOrDecrypt(String key, int mode, InputStream is, OutputStream os) throws Throwable {
DESKeySpec dks = new DESKeySpec(key.getBytes());
SecretKeyFactory skf = SecretKeyFactory.getInstance("DES");
SecretKey desKey = skf.generateSecret(dks);
Cipher cipher = Cipher.getInstance("DES"); // DES/ECB/PKCS5Padding for SunJCE
if (mode == Cipher.ENCRYPT_MODE) {
cipher.init(Cipher.ENCRYPT_MODE, desKey);
CipherInputStream cis = new CipherInputStream(is, cipher);
doCopy(cis, os);
} else if (mode == Cipher.DECRYPT_MODE) {
cipher.init(Cipher.DECRYPT_MODE, desKey);
CipherOutputStream cos = new CipherOutputStream(os, cipher);
doCopy(is, cos);
}
}
public static void doCopy(InputStream is, OutputStream os) throws IOException {
byte[] bytes = new byte[64];
int numBytes;
while ((numBytes = is.read(bytes)) != -1) {
os.write(bytes, 0, numBytes);
}
os.flush();
os.close();
is.close();
}
}
What I have tried:
I have tried using Code Convert and Jsc in WIndows which drops out the Compilation Giving Errors ,
I tried the DES using Crypto in .Net Which has difference in the convertion, Once you Convert from .Net and it Wont Extract from Java, So i need this above Code to Convert to a DLL to plug as a reference to my VB project.