2017-10-02 20 views
0

으로 변환하는 방법이 Java 코드를 C#으로 변환하려면 어떻게해야합니까?두 개의 업데이트 문을 사용하여 Java MessageDigest를 C#

 var hash = HashAlgorithm.Create("SHA-1"); 
     hash.ComputeHash(a); 
     hash.ComputeHash(b); 

하지만 ComputeHash 실제로 바이트 []를 반환하기 때문에이 올바른 방향으로 가고 있다고 생각하지 않습니다

byte[] a = ...some byte array...; 
    byte[] b = ...some byte array...; 

    MessageDigest m_Hash = MessageDigest.getInstance("SHA-1"); 
    m_Hash.update(a); 
    m_Hash.update(b); 
    byte[] ub = m_Hash.digest(); 

지금까지 내가 가지고있다.

답변

0

그래서 ... 업데이트가 바로 바이트 배열 ... 나는이 작업을 수행하는 함수를 썼다 추가하고 다음과 같습니다 것 같습니다 :

var hash = HashAlgorithm.Create("SHA-1"); 
    byte[] ub = hash.ComputeHash(AppendArrays(a, b)); 

    public byte[] AppendArrays(byte[] b1, params byte[][] others) 
    { 
     int n = b1.Length; 
     foreach (var other in others) 
      n += other.Length; 

     var result = new byte[n]; 

     n = 0; 
     Array.Copy(b1, 0, result, n, b1.Length); 
     n += b1.Length; 
     foreach (var other in others) 
     { 
      Array.Copy(other, 0, result, n, other.Length); 
      n += other.Length; 
     } 

     return result; 
    }