如何将该python函数转换为C#?

我试图翻译在API中使用的python函数来签署请求,但没有成功,这是python函数的代码:

def sign(msg, secret):
    msg = bytearray(msg.encode("utf-8"))
    hmac_key = base64.b64decode(secret)
    signature = hmac.new(hmac_key, msg, hashlib.sha256)
    signature_b64 = base64.b64encode(signature.digest()).decode("utf-8")
    return signature_b64

有任何想法吗?