本文整理汇总了C#中System.Security.Cryptography.SHA1CryptoServiceProvider类的典型用法代码示例。如果您正苦于以下问题:C# System.Security.Cryptography.SHA1CryptoServiceProvider类的具体用法?C# System.Security.Cryptography.SHA1CryptoServiceProvider怎么用?C# System.Security.Cryptography.SHA1CryptoServiceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Security.Cryptography.SHA1CryptoServiceProvider类属于命名空间,在下文中一共展示了System.Security.Cryptography.SHA1CryptoServiceProvider类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSha1Hash
public static string GetSha1Hash(this string value)
{
var encoding = new UTF8Encoding();
var hash = new System.Security.Cryptography.SHA1CryptoServiceProvider();
var hashed = hash.ComputeHash(encoding.GetBytes(value));
return encoding.GetString(hashed);
}
示例2: GetSHA1Hash
public static string GetSHA1Hash(string pathName)
{
string strResult = "";
string strHashData = "";
byte[] arrbytHashValue;
System.IO.FileStream oFileStream = null;
System.Security.Cryptography.SHA1CryptoServiceProvider oSHA1Hasher =
new System.Security.Cryptography.SHA1CryptoServiceProvider();
try
{
oFileStream = GetFileStream(pathName);
arrbytHashValue = oSHA1Hasher.ComputeHash(oFileStream);
oFileStream.Close();
strHashData = System.BitConverter.ToString(arrbytHashValue);
strHashData = strHashData.Replace("-", "");
strResult = strHashData;
}
catch (System.Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "Error!",
System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Error,
System.Windows.Forms.MessageBoxDefaultButton.Button1);
}
return (strResult);
}
示例3: init
public void init()
{
// signature=java.security.Signature.getInstance("SHA1withRSA");
// keyFactory=KeyFactory.getInstance("RSA");
sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
cs = new System.Security.Cryptography.CryptoStream(System.IO.Stream.Null, sha1, System.Security.Cryptography.CryptoStreamMode.Write);
}
示例4: GetSHA1Hash
public static string GetSHA1Hash(string pathName)
{
string strResult = "";
string strHashData = "";
byte[] arrbytHashValue;
System.IO.FileStream oFileStream = null;
System.Security.Cryptography.SHA1CryptoServiceProvider oSHA1Hasher =
new System.Security.Cryptography.SHA1CryptoServiceProvider();
try
{
oFileStream = GetFileStream(pathName);
arrbytHashValue = oSHA1Hasher.ComputeHash(oFileStream);
oFileStream.Close();
strHashData = System.BitConverter.ToString(arrbytHashValue);
strHashData = strHashData.Replace("-", "");
strResult = strHashData;
}
catch (System.Exception)
{
}
return (strResult);
}
示例5: Generate
public static string Generate()
{
// Generate random
var rnd = new System.Security.Cryptography.RNGCryptoServiceProvider();
var entropy = new byte[bytes - 4];
try {
rnd.GetBytes(entropy);
} finally {
rnd.Dispose();
}
// Hash
var sha = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] hash;
try {
hash = sha.ComputeHash(entropy);
} finally {
sha.Dispose();
}
// Compute output
var raw = new byte[bytes];
Array.Copy(entropy, 0, raw, 0, bytes - 4);
Array.Copy(hash, 0, raw, bytes - 4, 4);
// Convert to Base64
return Convert.ToBase64String(raw).Replace('+', '!').Replace('/', '~');
}
示例6: GetFeatureOfHuman
public static Guid GetFeatureOfHuman(byte[] humanDescriptionBytes)
{
byte[] hashedBytes = new System.Security.Cryptography.SHA1CryptoServiceProvider().ComputeHash(humanDescriptionBytes);
Array.Resize(ref hashedBytes, 16);
return new Guid(hashedBytes);
}
示例7: GetCryptographyString
private static string GetCryptographyString(string strSource)
{
System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] bytes = sha1.ComputeHash(System.Text.Encoding.Default.GetBytes(strSource));
string result = BitConverter.ToString(bytes, 4, 8).Replace("-","");
return result;
}
示例8: createHash
/// <summary>
/// Retorna el hash SHA1 de la cadena de texto que recibe como parámetro.
/// </summary>
/// <param name="unHashed">Cadena de texto a encriptar.</param>
/// <returns>Hash de la cadena de texto. SHA1.</returns>
public static string createHash(string unHashed)
{
System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(unHashed);
data = x.ComputeHash(data);
return Convert.ToBase64String(data);
}
示例9: GenerateAuthorizationToken
private static string GenerateAuthorizationToken(string passTypeIdentifier, string serialNumber)
{
using (System.Security.Cryptography.SHA1CryptoServiceProvider hasher = new System.Security.Cryptography.SHA1CryptoServiceProvider())
{
byte[] data = Encoding.UTF8.GetBytes(passTypeIdentifier.ToLower() + serialNumber.ToLower() + mAuthorizationKey);
return System.BitConverter.ToString(hasher.ComputeHash(data)).Replace("-", string.Empty).ToLower();
}
}
示例10: Hash
private static string Hash(string toHash)
{
System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(toHash);
data = x.ComputeHash(data);
string o = BitConverter.ToString(data).Replace("-", "").ToUpper();
return o;
}
示例11: Main
public static string root = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); // string root points to MyDocuments
#endregion Fields
#region Methods
static void Main(string[] args)
{
if (args.Length > 0)
{
if (args[0] == "-v")
{
Console.WriteLine("asdasd");
if (File.Exists(prefs + "/gkey"))
{
using (System.IO.StreamReader sr = new System.IO.StreamReader(prefs + "/gkey"))
{
string data = sr.ReadToEnd();
string[] f = data.Split('\n');
sr.Dispose();
if (f[0] == "accepted")
{
string HASH = f[1].ToString();
using (System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
{
string hashsum = string.Empty; // Empty storage allocator
byte[] da = sha1.ComputeHash(Encoding.Unicode.GetBytes(prefs + "/gkey")); // byte array
foreach (byte by in data)
{
hashsum += String.Format("{0,2:X2}", by); // :-)
}
if (hashsum.ToString() != HASH.ToString())
{
Console.ForegroundColor = ConsoleColor.Red;
Console.Write("SECURITY COMPROMISED!\n\nSHA1 HASH MODIFIED!\nRECORD DOES NOT MATCH G_KEY!\n\nCACHE WILL BE DELETED FOR SECURITY.");
Console.Read();
}
else ;
sha1.Dispose();
try
{
Directory.Delete(prefs);
}
catch { ; }
}
}
}
}
}
}
else
{
Console.Write("This is not a standalone application.");
}
}
示例12: EncryptToSHA1
public string EncryptToSHA1(string str)
{
System.Security.Cryptography.SHA1CryptoServiceProvider sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] str1 = System.Text.Encoding.UTF8.GetBytes(str);
byte[] str2 = sha1.ComputeHash(str1);
sha1.Clear();
(sha1 as IDisposable).Dispose();
return Convert.ToBase64String(str2);
}
示例13: GetSHA1
public static string GetSHA1(string pwdata_s)
{
System.Security.Cryptography.SHA1CryptoServiceProvider osha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider();
ASCIIEncoding enc = new ASCIIEncoding();
byte[] pwdata_b = enc.GetBytes(pwdata_s);//password(string) to byte[]
byte[] pwsha1_b = osha1.ComputeHash(pwdata_b);//ToHash
string pwsha1_s = BitConverter.ToString(pwsha1_b).Replace("-", "");//hash to string
return pwsha1_s;
}
示例14: sha1
public string sha1(string input)
{
byte[] hash;
using (var sha1 = new System.Security.Cryptography.SHA1CryptoServiceProvider())
hash = sha1.ComputeHash(Encoding.Unicode.GetBytes(input));
var sb = new StringBuilder();
foreach (byte b in hash) sb.AppendFormat("{0:x2}", b);
return sb.ToString();
}
示例15: HashString
public static string HashString(string Value)
{
System.Security.Cryptography.SHA1CryptoServiceProvider x = new System.Security.Cryptography.SHA1CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(Value);
data = x.ComputeHash(data);
string ret = "";
for (int i = 0; i < data.Length; i++)
ret += data[i].ToString("x2").ToLower();
return ret;
}