반응형
이글에서는 SHA256
클래스를 통해 데이터를 암호화하는 방법을 설명한다.
SHA256
클래스를 사용하려면 Cryptography 네임스페이스를 사용해야한다.
using System.Security.Cryptography;
Crytography 네임스페이스는 데이터의 암호화 뿐만아니라
난수 생성, 메시지 인증 등의 수많은 기능들을 제공한다.
다음의 코드는 SHA256
을 통해 데이터를 단방향 암호화하는 메서드이다.
public string SHA256Encrypt(string data)
{
var bytes = Encoding.UTF8.GetBytes(data);
var hash = new SHA256CryptoServiceProvider().ComputeHash(bytes);
var encryptedData = new StringBuilder();
foreach(var h in hash) encryptedData.AppendFormat("{0:x2}", h);
return encryptedData.ToString();
}
반응형
'프로그래밍 > .NET' 카테고리의 다른 글
Firestore 연동하기 (0) | 2022.02.06 |
---|---|
관리자 권한으로 프로젝트 실행하기 (1) | 2021.07.18 |
.net core 설치 in terminal (0) | 2021.02.25 |
람다 (Lambda) (0) | 2020.12.11 |
델리게이트 (Delegate) (0) | 2020.12.11 |