๐Ÿ˜œ

์ญˆ๋‚˜์•„๋น  ๋ธ”๋กœ๊ทธ

JUNA
STUDIO

[C#] Encrypting User Passwords Using the HMACSHA256 Class

๋ฐœํ–‰์ผ: Jan, 2025
์กฐํšŒ์ˆ˜: 2
๋‹จ์–ด์ˆ˜: 86

Table of Contents

Introduction

By using the HMACSHA256 class in C#, you can easily convert a user's password into an encrypted string with very simple code.

Code Example


    public static class CredentialHelper
    {
        public static string GetHMACSHA256Hash(string username, string password)
        {
            var key = Encoding.ASCII.GetBytes(username);
            var data = Encoding.ASCII.GetBytes(password);
            return Convert.ToBase64String(new HMACSHA256(key).ComputeHash(data));
        }
    }

Usage

As shown above, you can create a static class and use the function to generate a hash string from the username and password entered by the user. You can then store this hash string and compare it with the hash generated from the username/password combination entered by the user during login to verify.

Tags: #HMACSHA256#C##password encryption#hashing#credential helper
JUNA BLOG VISITORS
Today
7
 (
updown
-7
)
Total
657
 (
updown
+7
)

ยฉ 2025 juniyunapapa@gmail.com.