What is the equivalent in c # of the following java code?
- import java.security.MessageDigest;
- import javax.xml.bind.DatatypeConverter;
- public String algoritmoHash(byte[] pArchivo, String algorithm) {
- String hashValue = "";
- try {
- MessageDigest messageDigest = MessageDigest.getInstance(algorithm);
- messageDigest.update(pArchivo);
- byte[] digestedBytes = messageDigest.digest();
- hashValue = DatatypeConverter.printHexBinary(digestedBytes).toLowerCase();
- }
- catch (Exception e) {
- System.out.println("Error generando Hash");
- }
- return hashValue;
- }
And what is the equivalent of this other java code?
- import java.util.zip.Checksum;
- import java.util.zip.CRC32;
- public String calCrc32(byte[] data) {
- Checksum checksum = new CRC32();
- checksum.update(data, 0, data.length);
- long checksumValue = checksum.getValue();
- String hex = Long.toHexString(checksumValue).toUpperCase();
- while (hex.length() < 8) {
- hex = "0" + hex;
- }
- return hex;
- }