我需要将下面的Java脚本代码转换为DLL链接到Vb.Net应用程序可以帮助我。 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; // DES需要至少8个字符 if(args.length == 1) { String fileName = args [ 0]; System.out.println(加密+ fileName); 字符串encFileName = args [0] +。enc; FileInputStream fis = new FileInputStream(fileName); FileOutputStream fos = new FileOutputStream(encFileName); 加密(密钥,fis,fos); System.out.println(加密文件名+ encFileName); } 其他 { System.out.println(无效的命令行参数); } } catch(Throwable e){ e.printStackTrace(); } } public static void encrypt (String key,InputStream is,OutputStream os)抛出Throwable { encryptOrDecrypt(key,Cipher.ENCRYPT_MODE,is,os); } public static void decrypt(String key,InputStream is,OutputStream os)抛出Throwable { encryptOrDecrypt(key,Cipher.DECRYPT_MODE,is,os); } public static void encryptOrDecrypt(String key,int mode,InputStream is,OutputStream os)抛出Throwable { DESKeySpec dks = new DESKeySpec(key.getBytes()); SecretKeyFactory skf = SecretKeyFactory.getInstance(DES); Sec retKey desKey = skf.generateSecret(dks); Cipher cipher = Cipher.getInstance(DES); //用于SunJCE的DES / ECB / PKCS5Padding if(mode == Cipher.ENCRYPT_MODE){ cipher.init(Cipher.ENCRYPT_MODE) ,desKey); CipherInputStream cis = new CipherInputStream(is,cipher); doCopy(cis,os); }否则如果( mode == Cipher.DECRYPT_MODE){ cipher.init(Cipher.DECRYPT_MODE,desKey); CipherOutputStream cos = new CipherOutputStream(os,cipher); doCopy(是,cos); } } public static void doCopy( InputStream是,OutputStream os)抛出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(); } } 我的尝试: 我尝试过使用Code在WIndows中转换和Jsc消除了编译给出的错误, 我在.Net中使用Crypto尝试了DES。转换后有转换的差异,转换后。 Net和它不会从Java中提取,所以我需要上面的代码转换为DLL插件作为我的VB项目的引用。
解决方案过去那里有一种叫做 Visual J#的东西,虽然它已经停产,但它仍然可以下载它: Visual J#Home [ ^ ]
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.
解决方案 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[^]更多推荐
将java代码转换为.NET DLL
发布评论