-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsha256-cipher.cs
32 lines (27 loc) · 896 Bytes
/
sha256-cipher.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Security.Cryptography;
using System.Text;
namespace Cryptography_Algorithms
{
class Sha256Cipher
{
static void Main(string[] args)
{
Console.WriteLine("Enter message to encrypt: ");
string encryptMessage = Console.ReadLine();
string cipherText = Encrypt(encryptMessage);
Console.WriteLine("\nEncrypted message: " + cipherText);
Console.ReadLine();
}
static string Encrypt(string secretMessage)
{
using (SHA256 sha256Hash = SHA256.Create())
{
byte[] sourceBytes = Encoding.UTF8.GetBytes(secretMessage);
byte[] hashBytes = sha256Hash.ComputeHash(sourceBytes);
string hash = BitConverter.ToString(hashBytes).Replace("-", "");
return hash;
}
}
}
}