Mario Figueroa

Mario Figueroa

  • NA
  • 16
  • 2.4k

c# equivalent of java

Jul 30 2019 8:40 PM
What is the equivalent in c # of the following java code?
  1. import java.security.MessageDigest;  
  2. import javax.xml.bind.DatatypeConverter;  
  3. public String algoritmoHash(byte[] pArchivo, String algorithm) {  
  4.    String hashValue = "";  
  5.    try {  
  6.          MessageDigest messageDigest = MessageDigest.getInstance(algorithm);  
  7.          messageDigest.update(pArchivo);  
  8.          byte[] digestedBytes = messageDigest.digest();  
  9.          hashValue = DatatypeConverter.printHexBinary(digestedBytes).toLowerCase();  
  10.    }  
  11.    catch (Exception e) {  
  12.       System.out.println("Error generando Hash");  
  13.    }  
  14.    return hashValue;  
  15. }  
And what is the equivalent of this other java code?
  1. import java.util.zip.Checksum;  
  2. import java.util.zip.CRC32;  
  3. public String calCrc32(byte[] data) {  
  4.    Checksum checksum = new CRC32();  
  5.    checksum.update(data, 0, data.length);  
  6.    long checksumValue = checksum.getValue();  
  7.    String hex = Long.toHexString(checksumValue).toUpperCase();  
  8.    while (hex.length() < 8) {  
  9.       hex = "0" + hex;  
  10.    }  
  11.    return hex;  
  12. }  

Answers (1)