More Group Sites
Education Books
School Rankings
Jobless Net
Better Home
Enviro++
更好教育论坛


Help | Subscribe/Unsubscribe | Rules | Other Group Sites: Better Education | Better Education Forum
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Share
Options
View
Go to last post Go to first unread
hong  
#1 Posted : Friday, 21 September 2018 9:10:32 PM(UTC)
hong

Rank: Administration

Reputation:

Groups: AcademicCoachingSchool, admin, Administration, BookSeller, CatholicSchool, CoachingAdult, CoachingProfessional, CoachingSports, ExtraCurriculumCoaching, IndependentSchool, Moderator, MusicTeacher, PrivateSchool, PublicSchool, SelectiveSchool, tutor
Joined: 23/11/2008(UTC)
Posts: 519

C# generate HMAC SHA256
HMAC (Hash-based Message Authentication Code) is a specific type of message authentication code (MAC) involving a cryptographic hash function (eg SHA256) and a secret cryptographic key.

Code:
public static byte[] GenerateHMAC(String text, byte[] keyBytes)
{

    var encoding = new ASCIIEncoding();

    var textBytes = encoding.GetBytes(text);

    Byte[] hashBytes;

    using (var hash = new HMACSHA256(keyBytes))

        hashBytes = hash.ComputeHash(textBytes);

    return hashBytes;

}


You can use a series of encryption keys including time, product ID / serial number or even a url to generate an HMAC.
Code:
var hmacBytes= GenerateHMAC(utctime, HMAC_KEY);
hmacBytes = GenerateHMAC(<product ID or serial number as a string>, hmacBytes);
hmacBytes = GenerateHMAC(url, hmacBytes);


You can test the function against an online HMAC Generator.

Edited by user Friday, 21 September 2018 9:20:04 PM(UTC)  | Reason: Not specified

Sponsor
Rss Feed  Atom Feed
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.