CryptoUtils
This commit is contained in:
38
Scrummer/Code/CryptoUtils.cs
Normal file
38
Scrummer/Code/CryptoUtils.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
|
||||
namespace Scrummer.Code
|
||||
{
|
||||
public class CryptoUtils
|
||||
{
|
||||
public static string GetSHA1(string str)
|
||||
{
|
||||
SHA1 sha1 = SHA1Managed.Create();
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
byte[] stream = null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
stream = sha1.ComputeHash(encoding.GetBytes(str));
|
||||
for (int i = 0; i < stream.Length; i++) sb.AppendFormat("{0:x2}", stream[i]);
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string GetRandString(int len)
|
||||
{
|
||||
byte[] bytes = new byte[len];
|
||||
var cryptoRandom = new System.Security.Cryptography.RNGCryptoServiceProvider();
|
||||
cryptoRandom.GetBytes(bytes);
|
||||
|
||||
UTF8Encoding encoding = new UTF8Encoding();
|
||||
return encoding.GetString(bytes);
|
||||
}
|
||||
|
||||
public static string GetCryptoToken()
|
||||
{
|
||||
return CryptoUtils.GetSHA1(CryptoUtils.GetRandString(10));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -72,6 +72,7 @@
|
||||
<Compile Include="Code\Controls\CLabel.cs" />
|
||||
<Compile Include="Code\Controls\CTextBox.cs" />
|
||||
<Compile Include="Code\Controls\IValidableControl.cs" />
|
||||
<Compile Include="Code\CryptoUtils.cs" />
|
||||
<Compile Include="Code\Entities\Message.cs" />
|
||||
<Compile Include="Code\GlobalErrorHandler.cs" />
|
||||
<Compile Include="Code\JSON\ParserContext.cs" />
|
||||
|
||||
Reference in New Issue
Block a user