I will help translate this function into C #'s thanks to the big hacker of PHP ~~

Source: Internet
Author: User
UsingSystem; usingSystem. Text; usingSystem. Security. Cryptography; publicclassProgram {privateconststringkeykey; privateconststringmessagemessage; cipher. UTF8; static

Using System; using System. text; using System. security. cryptography; public class Program {private const string key = "key"; private const string message = "message"; private static readonly Encoding encoding = Encoding. UTF8; static

Using System;

Using System. Text;

Using System. Security. Cryptography;

Public class Program {

Private const string key = "key ";

Private const string message = "message ";

Private static readonly Encoding encoding = Encoding. UTF8;

Static void Main (string [] args ){

Var keyByte = encoding. GetBytes (key );

Using (var hmacsha256 = new HMACSHA256 (keyByte) {hmacsha256.ComputeHash (encoding. GetBytes (message ));

Console. WriteLine ("Result: {0}", ByteToString (hmacsha256.Hash ));

}

}

Static string ByteToString (byte [] buff ){

String sbinary = "";

For (int I = 0; I <buff. Length; I ++)

Sbinary + = buff [I]. ToString ("X2 ");

/* Hex format */return sbinary ;}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.