Click here to Skip to main content
15,886,919 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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.
Posted
Updated 8-Feb-19 2:09am
Comments
Richard MacCutchan 8-Feb-19 7:00am    
Java does not generate code that is compatible with .NET, nor does it create DLL libraries. You need to find a different solution. If you just want to use encryption then study the .NET encryption classes.
Devendra Godawatta 8-Feb-19 7:46am    
No there are tools which can be Converted to a DLL Wrapper Like Using JSC, WHat i want is not to convert the Java to .Net but to Convert it to a DLL, To Refer in .Net I dont have a Much of a Idea about Java Script to Modify this if some one knows Java He can do this i think
Richard MacCutchan 8-Feb-19 7:59am    
If you know that there are tools to convert it then you need to get hold of one of them and try it out. And please stop referring to this as Java script, it is just Java. Javscript is something completely different.
Dave Kreskowiak 8-Feb-19 8:36am    
Java does not compile to .DLL's. Ever.

If you want a .DLL, you're going to have to convert the code into another language and framework that compiled down to a .DLL.

And if by "Help", you mean "do the work for you", you've come to the wrong site.

1 solution

In the past there was something called Visual J#, and although it is discontinued it might be possible to still download it: Visual J# Home[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900