Rename to VAR.Focus

This commit is contained in:
2015-06-26 02:23:21 +02:00
parent 58d51ee3b7
commit 175fad80e4
52 changed files with 71 additions and 98 deletions

View File

@@ -0,0 +1,41 @@
using System;
using System.Security.Cryptography;
using System.Text;
namespace VAR.Focus.Web.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 RNGCryptoServiceProvider();
cryptoRandom.GetBytes(bytes);
UTF8Encoding encoding = new UTF8Encoding();
return encoding.GetString(bytes);
}
public static string GetCryptoToken()
{
return CryptoUtils.GetSHA1(CryptoUtils.GetRandString(10));
}
public static string GetHashedPassword(string password, string passwordSalt)
{
return CryptoUtils.GetSHA1(String.Format("{1}{0}{1}", password, passwordSalt));
}
}
}