Convert Java to C#
<p>Could someone pls show me how to convert the following java code into C#. I've tried using TransformBlock to handle the multiple md.update calls but I keep getting the same hash each time - which is different from the java output.</p>

<p>Thanks.  </p>

<pre><code>public static String encrypt(String key, String value) {
    java.security.MessageDigest md = null;

    // System.out.println( "-"+key+"-" + "  -"+value+"-");
    try {
        md = java.security.MessageDigest.getInstance("MD5");
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }

    md.update(key.getBytes());
    md.update(value.getBytes());
    byte[] bb = md.digest();
    // System.out.println( bb.length );
    StringBuilder s = new StringBuilder("");

    for (byte element : bb) {
        s.append(byteToHex(element));
    }
    // System.out.println(s.toString());
    return s.toString();
}

public static String byteToHex(byte by) {
    int x = by;
    if (x &lt; 0) {
        x = 256 + x;
    }

    // System.out.println(x);
    int a, b;
    b = x % 16;
    a = (x - b) / 16;

    // System.out.println( a );
    // System.out.println( b );

    char q;

    if (a &lt;= 9) {
        q = (char) (a + 48);
    } else {
        q = (char) (a - 10 + 65);
    }

    char w;
    if (b &lt;= 9) {
        w = (char) (b + 48);
    } else {
        w = (char) (b - 10 + 65);
    }

    return "" + q + "" + w;
}
</code></pre>
