-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d0652f2
commit 0369e85
Showing
4 changed files
with
115 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Runtime.CompilerServices; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using System.Security.Cryptography; | ||
|
||
namespace Task3 | ||
{ | ||
class Hash | ||
{ | ||
public string Key { get; private set; } | ||
|
||
public string HMAC { get; private set;} | ||
|
||
byte[] CreateKey() | ||
{ | ||
byte[] key = new byte[32]; | ||
var a = RandomNumberGenerator.Create(); | ||
a.GetBytes(key); | ||
string keyString = string.Empty; | ||
foreach (byte x in key) | ||
{ | ||
keyString += String.Format("{0:x2}", x); | ||
} | ||
|
||
this.Key = keyString; | ||
return key; | ||
} | ||
|
||
public void CalculateHMAC(string text) | ||
{ | ||
|
||
HMACSHA256 hashObject = new HMACSHA256(this.CreateKey()); | ||
var signature = hashObject.ComputeHash(Encoding.UTF8.GetBytes(text)); | ||
var encodedSignature = Convert.ToBase64String(signature); | ||
this.HMAC = encodedSignature; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters