任何人都可以将下面的java代码翻译成c#。请帮我解决这个问题 [英] Can anyone translate the below java code to c#. Please help me to solve the issue

查看:63
本文介绍了任何人都可以将下面的java代码翻译成c#。请帮我解决这个问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  import  java.security.MessageDigest 
public SecureHash
{
静态 final char [] HEX = new char []
{' 0'' 1' 2'' 3'' 4'' 5'' 6'' 7'' 8'' 9'' a'' b'' c' ' d'' e'' f' };}

静态 字符串 hex( byte [] input)
{
StringBuffer sb = new StringBuffer(input.length * 2 );
for int i = 0; i< input.length; i ++){
sb.append(HEX [(inout [i]>> 4)& 0 * f]);
sb.append(HEX [input [i]& 0 * f]);
}
return sb.tostring();
}

public static 字符串 genSecureHash(字符串 OriginalString)
{
MessageDigest md = null;
byte [] ba = null;
尝试 {
md = MessageDigest.getInstance( SHA-256);
ba = md.digest(originalString.getBytes( ISO-8859-1) );
} catch (例外e){}
return hex(ba);
}
}







这是我试过的。





  public   static   readonly   char  [] HEX =  new   char  [] {'  0''  1' '  2''  3''  4''  5''  6''  7''  8''  9''  a''  b''  c' '  d''  e''  f'}; 

public static byte [] md5Of(IList< string> list)
{
try
{
StringBuilder rawString = < span class =code-keyword> new StringBuilder();
foreach string elem in list)
{
rawString.Append(elem);
}
byte [] digest = ConvertStringToMD51(rawString.ToString());
return 摘要;
}
catch (例外e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
返回 null ;
}

public static byte [] ConvertStringToMD51( string ClearText)
{
Encoding enc = Encoding.GetEncoding( ISO-8859-1);
byte [] ByteData = enc.GetBytes(ClearText);
MD5基因= MD5.Create();
byte [] HashData = gene.ComputeHash(ByteData);
StringBuilder oSb = new StringBuilder();
for int x = 0 ; x < HashData.Length; x ++)
{
oSb.Append(HashData [x] .ToString( x2));
}
return Encoding.Unicode.GetBytes(oSb.ToString());
}

public static string hexdigit( byte [] input)
{
char [] b16 = new char [input.Length * 2 ];
int i = 0 ;
foreach byte c in 输入)
{
int low = c& 0xF;
int high =(c& 0xF0)>> 4 ;
b16 [(i ++)] = HEX [高];
b16 [(i ++)] = HEX [低];
}
return new string (B16);
}





我的尝试:



请解决此问题。我不懂java。我无法将该类用于C#

解决方案

引用:

可以任何人都将以下java代码翻译成c#。请帮我解决问题



你的问题不是获得帮助,而是免费请求我的工作。

如果你希望有人做你的工作,考虑聘请专业的程序员

聘请自由职业者&在线查找自由职业者 - 自由职业者 [ ^ ]

Quote:

我不懂java。



即使你不懂Java ,你应该能够理解其中的大部分,你应该能够显示至少部分翻译。


我知道我有点迟到了,但这里是< a href =https://www.google.com.au/search?q=java+to+c%23&oq=java+to+c%23&aqs=chrome..69i57j0l2j69i65l2j69i60.3637j0j1&sourceid=chrome& ; ie = UTF-8> Google搜索 [ ^ ]起点发现:



* 帮助你的6个最佳工具u将Java转换为C#源代码»CODECALL [ ^ ]


不要尝试将其转换为C#,而是重写它以便正确使用。 NET加密功能。请参阅加密数据Microsoft Docs [ ^ ]。

import java.security.MessageDigest
public class SecureHash
{
   static final char[] HEX = new char[]
   { '0', '1', '2', '3', '4', '5', '6', '7','8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };}

   static String hex(byte[] input) 
   {
       StringBuffer sb = new StringBuffer(input.length * 2);
        for (int i =0;i<input.length;i++) {
           sb.append(HEX[(inout[i]>>4) & 0*f]);
           sb.append(HEX[input[i] & 0*f]);
        }
        return sb.tostring();
   }
   
   public static String genSecureHash(String OriginalString)
   {
       MessageDigest md = null;
       byte[] ba = null;
       try{
          md = MessageDigest.getInstance("SHA-256");
          ba = md.digest(originalString.getBytes("ISO-8859-1"));
      }catch(Exception e){}
      return hex(ba);
   }
}




This is what i tried.


public static readonly char[] HEX = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };

public static byte[] md5Of(IList<string> list)
{
try
{
StringBuilder rawString = new StringBuilder();
foreach (string elem in list)
{
rawString.Append(elem);
}
byte[] digest = ConvertStringToMD51(rawString.ToString());
return digest;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.Write(e.StackTrace);
}
return null;
}

public static byte[] ConvertStringToMD51(string ClearText)
{
Encoding enc = Encoding.GetEncoding("ISO-8859-1");
byte[] ByteData = enc.GetBytes(ClearText);
MD5 gene = MD5.Create();
byte[] HashData = gene.ComputeHash(ByteData);
StringBuilder oSb = new StringBuilder();
for (int x = 0; x < HashData.Length; x++)
{
oSb.Append(HashData[x].ToString("x2"));
}
return Encoding.Unicode.GetBytes(oSb.ToString());
}

public static string hexdigit(byte[] input)
{
char[] b16 = new char[input.Length * 2];
int i = 0;
foreach (byte c in input)
{
int low = c & 0xF;
int high = (c & 0xF0) >> 4;
b16[(i++)] = HEX[high];
b16[(i++)] = HEX[low];
}
return new string(b16);
}



What I have tried:

Pls resolve the issue. I dont know java. i am unable to use the the class for C#

解决方案

Quote:

Can anyone translate the below java code to c#. Please help me to solve the issue


Your question is not about "getting help", it is a "do my job for free request".
If you want someone to do your work, think about hiring a professional programmer
Hire Freelancers & Find Freelance Jobs Online - Freelancer[^]

Quote:

I dont know java.


Even if you don't know Java, you should be able to understand most of it, you should be able to show at least partial translation.


I know that I am a little late to the party, but here is a Google Search[^] starting point which found this:

* 6 Best Tools to Help You Convert Java to C# Source Code » CODECALL[^]


Don't try to convert it to C#, but rewrite it so it correctly uses the .NET encryption features. See Encrypting Data | Microsoft Docs[^].


这篇关于任何人都可以将下面的java代码翻译成c#。请帮我解决这个问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆