以上是java的一个加密解密算法,现在要根据这个算法编写C#算法,请各位高手给出代码。多谢。分不够可以加,在线等。
public class DES
{
private byte[] EncodAndDecodeKey = null;
private static String strAlgorithm = "DESede";
public void initPhar()
{
String strKey = "1234567890987650abcdefgh";
int size = strKey.length();
byte[] temKey = strKey.getBytes();
byte[] EncodAndDecodeKey = new byte[size];
for (int i = 0; i < size; i++) {
EncodAndDecodeKey[i] = temKey[i];
}
}
public void DecryptData(String strEnDataFile, String strDeDataFile)
{
try
{
SecretKeySpec destmp = new SecretKeySpec(this.EncodAndDecodeKey, "DESede");
SecretKey theKey = destmp;
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(2, theKey);
FileInputStream in = new FileInputStream(strEnDataFile);
FileOutputStream out = new FileOutputStream(strDeDataFile);
int len;
while ((len = in.read()) > 0) {
byte[] Data = new byte[len];
in.read(Data);
byte[] decryptedtext = cipher.doFinal(Data);
out.write(decryptedtext);
}
in.close();
out.close();
}
catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
}
catch (NoSuchPaddingException e2) {
e2.printStackTrace();
}
catch (Exception e3) {
e3.printStackTrace();
}
catch (NoSuchMethodError e4) {
e4.printStackTrace();
}
}
public void DecryptData(String strEnDataFile, String strDeDataFile)
{
try
{
SecretKeySpec destmp = new SecretKeySpec(this.EncodAndDecodeKey, "DESede");
SecretKey theKey = destmp;
Cipher cipher = Cipher.getInstance("DESede");
cipher.init(2, theKey);
FileInputStream in = new FileInputStream(strEnDataFile);
FileOutputStream out = new FileOutputStream(strDeDataFile);
int len;
while ((len = in.read()) > 0) {
byte[] Data = new byte[len];
in.read(Data);
byte[] decryptedtext = cipher.doFinal(Data);
out.write(decryptedtext);
}
in.close();
out.close();
}
catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
}
catch (NoSuchPaddingException e2) {
e2.printStackTrace();
}
catch (Exception e3) {
e3.printStackTrace();
}
catch (NoSuchMethodError e4) {
e4.printStackTrace();
}
}
}
以上是java的一个加密解密算法,现在要根据这个算法编写C#算法,请各位高手给出代码。多谢。分不够可以加,在线等。