本文整理汇总了C#中System.Security.Cryptography.SHA256CryptoServiceProvider类的典型用法代码示例。如果您正苦于以下问题:C# SHA256CryptoServiceProvider类的具体用法?C# SHA256CryptoServiceProvider怎么用?C# SHA256CryptoServiceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SHA256CryptoServiceProvider类属于System.Security.Cryptography命名空间,在下文中一共展示了SHA256CryptoServiceProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateHash
internal static string GenerateHash(this string input)
{
HashAlgorithm hashAlgorithm = new SHA256CryptoServiceProvider();
var byteValue = System.Text.Encoding.UTF8.GetBytes(input);
var byteHash = hashAlgorithm.ComputeHash(byteValue);
return Convert.ToBase64String(byteHash);
}
示例2: Hash
/// <summary>
/// Hashes the specified arguments.
/// </summary>
/// <param name="args">The arguments.</param>
/// <returns>The hash</returns>
public static string Hash(params object[] args)
{
HashAlgorithm hashAlg = new SHA256CryptoServiceProvider();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(String.Concat(args));
byte[] bytHash = hashAlg.ComputeHash(bytValue);
return Convert.ToBase64String(bytHash);
}
示例3: GenerateCacheKeyHash
protected string GenerateCacheKeyHash(int tabId, string cacheKey)
{
byte[] hash = Encoding.ASCII.GetBytes(cacheKey);
var sha256 = new SHA256CryptoServiceProvider();
hash = sha256.ComputeHash(hash);
return string.Concat(tabId.ToString(), "_", ByteArrayToString(hash));
}
示例4: EncriptarPassword
private String EncriptarPassword(String password)
{
byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
SHA256 sha256 = new SHA256CryptoServiceProvider();
byte[] hashedPassword = sha256.ComputeHash(passwordBytes);
return BitConverter.ToString(hashedPassword).Replace("-","");
}
示例5: Encrypt
public static string Encrypt(string clearText)
{
byte[] arrbyte = new byte[clearText.Length];
SHA256 hash = new SHA256CryptoServiceProvider();
arrbyte = hash.ComputeHash(Encoding.UTF8.GetBytes(clearText));
return Convert.ToBase64String(arrbyte);
}
示例6: GetHashProvider
public static HashAlgorithm GetHashProvider(HashType type)
{
HashAlgorithm hash = null;
switch (type)
{
case HashType.MD5:
{
hash = new MD5CryptoServiceProvider();
break;
}
case HashType.SHA1:
{
hash = new SHA1CryptoServiceProvider();
break;
}
case HashType.SHA256:
{
hash = new SHA256CryptoServiceProvider();
break;
}
case HashType.SHA384:
{
hash = new SHA384CryptoServiceProvider();
break;
}
case HashType.SHA512:
{
hash = new SHA512CryptoServiceProvider();
break;
}
}
return hash;
}
示例7: HashStringSHA256
public static string HashStringSHA256(string valueUTF8)
{
byte[] valueBytes = Encoding.UTF8.GetBytes(valueUTF8);
SHA256CryptoServiceProvider shar2 = new SHA256CryptoServiceProvider();
byte[] hashBytes = shar2.ComputeHash(valueBytes);
return BitConverter.ToString(hashBytes).Replace("-", "");
}
示例8: CreateDoctorAcccount
public string CreateDoctorAcccount(string email, string dname, string pwd, string cfmpwd, string mobileno, string dob, string pip)
{
if (dname.Length == 0)
returnMessage += "Therapist Name cannot be blank <br />";
if (pwd.Length == 0)
returnMessage += "Password cannot be blank <br/>";
if (cfmpwd.Length == 0)
returnMessage += "Cofirm Passowrd cannot be blank <br/>";
if (mobileno.Length == 0)
returnMessage += "Mobile Number cannot be blank <br/>";
if (dob.Length == 0)
returnMessage += "Date of Birth cannnot be blank <br/>";
if (pip.Length == 0)
returnMessage += "Please Upload an image <br/>";
if (pwd != cfmpwd)
returnMessage += "Your passwords dont match <br/>";
if (returnMessage.Length == 0)
{
SHA256 sha = new SHA256CryptoServiceProvider();
byte[] data = Encoding.ASCII.GetBytes(pwd);
byte[] result = sha.ComputeHash(data);
string hashedpwd = Convert.ToBase64String(result);
AzureUserDAL doc = new AzureUserDAL(email, dname, hashedpwd, mobileno, dob, pip);
int noofRows = 0;
noofRows = doc.CreateDoctorProfile();
if (noofRows > 0)
returnMessage = "You Signed Up Succuesfully.";
else
returnMessage = "Error,Please try again";
}
return returnMessage;
}
示例9: HashPassword
public static string HashPassword(string password, string saltValue)
{
if (String.IsNullOrEmpty(password)) throw new ArgumentException("Password is null");
var encoding = new UnicodeEncoding();
var hash = new SHA256CryptoServiceProvider();
if (saltValue == null)
{
saltValue = GenerateSaltValue();
}
byte[] binarySaltValue = Convert.FromBase64String(saltValue);
byte[] valueToHash = new byte[SaltValueSize + encoding.GetByteCount(password)];
byte[] binaryPassword = encoding.GetBytes(password);
binarySaltValue.CopyTo(valueToHash, 0);
binaryPassword.CopyTo(valueToHash, SaltValueSize);
byte[] hashValue = hash.ComputeHash(valueToHash);
var hashedPassword = String.Empty;
foreach (byte hexdigit in hashValue)
{
hashedPassword += hexdigit.ToString("X2", CultureInfo.InvariantCulture.NumberFormat);
}
return hashedPassword;
}
示例10: GenerateToken
public static string GenerateToken(string @namespace, string eventHub, string publisher, string sharedAccessKeyName, string sharedAccessKey, DateTimeOffset expiry)
{
var unixEpoch = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
var timeSinceEpoch = expiry - unixEpoch;
var timeSinceEpochInMilliseconds = (long)timeSinceEpoch.TotalMilliseconds;
var url = Helper.BuildUrl(@namespace, eventHub, publisher);
var encodedUrl = HttpUtility.UrlEncode(url);
var signatureContent = string.Format("{0}\n{1}", encodedUrl, timeSinceEpochInMilliseconds);
var signatureContentAsBytes = Encoding.UTF8.GetBytes(signatureContent);
var provider = new SHA256CryptoServiceProvider();
var signatureAsBytes = provider.ComputeHash(signatureContentAsBytes);
var signature = Convert.ToBase64String(signatureAsBytes);
var token = string.Format(
"sr={0}&sig={1}&se={2}&skn={3}",
HttpUtility.UrlEncode(url),
HttpUtility.UrlEncode(signature),
timeSinceEpochInMilliseconds,
HttpUtility.UrlEncode(sharedAccessKeyName)
);
return token;
}
示例11: Signature
public static void Signature(Stream input, Stream output, string privateKey)
{
using (var sha = new SHA256CryptoServiceProvider())
using (var rsa = new RSACryptoServiceProvider())
{
// Compute hash
var buffer = ReadAllBytes(input);
var hash = sha.ComputeHash(buffer);
// RSA Initialize
rsa.FromXmlString(privateKey);
// format
var formatter = new RSAPKCS1SignatureFormatter(rsa);
formatter.SetHashAlgorithm("SHA256");
var signature = formatter.CreateSignature(hash);
// Krile Signature Package
var magic = MagicStr + ":" + signature.Length + ":";
var magicbytes = Encoding.UTF8.GetBytes(magic);
if (magicbytes.Length > 64)
throw new Exception("Magic bits too long.");
output.Write(magicbytes, 0, magicbytes.Length);
var padding = new byte[64 - magicbytes.Length];
output.Write(padding, 0, padding.Length);
output.Write(signature, 0, signature.Length);
output.Write(buffer, 0, buffer.Length);
}
}
示例12: SHA256
public static string SHA256(string str)
{
byte[] buffer = Encoding.UTF8.GetBytes(str);
SHA256CryptoServiceProvider SHA256 = new SHA256CryptoServiceProvider();
byte[] byteArr = SHA256.ComputeHash(buffer);
return BitConverter.ToString(byteArr);
}
示例13: Hash
public static string Hash(this string clear_text)
{
using (HashAlgorithm hash = new SHA256CryptoServiceProvider())
{
return Convert.ToBase64String(hash.ComputeHash(Encoding.UTF8.GetBytes(clear_text)));
}
}
示例14: HashPassword
private NewPassword HashPassword(NewPassword np)
{
HashAlgorithm hashAlg = null;
try
{
hashAlg = new SHA256CryptoServiceProvider();
byte[] bytValue = System.Text.Encoding.UTF8.GetBytes(np.GetSaltPassword());
byte[] bytHash = hashAlg.ComputeHash(bytValue);
np.SaltedHashedPassword = Convert.ToBase64String(bytHash);
}
catch (Exception e)
{
throw e;
}
finally
{
if (hashAlg != null)
{
hashAlg.Clear();
hashAlg.Dispose();
hashAlg = null;
}
}
return np;
}
示例15: CreateHashedPassword
public static string CreateHashedPassword(string password, string salt)
{
var sha256 = new SHA256CryptoServiceProvider();
byte[] passwordBytes = System.Text.Encoding.UTF8.GetBytes(password + salt);
byte[] hashedPasswordBytes = sha256.ComputeHash(passwordBytes);
return Convert.ToBase64String(hashedPasswordBytes);
}