本文整理汇总了C#中MD5类的典型用法代码示例。如果您正苦于以下问题:C# MD5类的具体用法?C# MD5怎么用?C# MD5使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MD5类属于命名空间,在下文中一共展示了MD5类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Map
static Map()
{
#if HASH
hash = MD5.Create();
#endif
NameMap = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
}
示例2: GenerateMD5
private static void GenerateMD5()
{
if (md5Hash == null)
{
md5Hash = MD5.Create();
}
}
示例3: Main
public static void Main()
{
var triplet = new Regex(@"(.)\1\1");
md5 = MD5.Create();
salt = Console.ReadLine();
int keysFound = 0;;
int index = -1;
while (keysFound < 64) {
index++;
string hash = GetHash(index);
Match match = triplet.Match(hash);
if (match.Success) {
char letter = match.Groups[0].Value[0];
var fiveOfThem = new Regex(new String(letter, 5));
for (int j = index + 1; j <= index + 1000; j++) {
if (fiveOfThem.IsMatch(GetHash(j))) {
keysFound++;
break;
}
}
}
hashCache.Remove(index);
}
Console.WriteLine(index);
}
示例4: CalculateMD5Incremental
public void CalculateMD5Incremental(byte[] pBuf, int bytesRead)
{
if (md5Incremental == null)
md5Incremental = MD5.Create();
dummy = pBuf;
md5Incremental.TransformBlock(pBuf, 0, bytesRead, null, 0);
}
示例5: EncodeTest
public void EncodeTest()
{
const string data = "i am testing";
MD5 md5 = new MD5();
var result = md5.Encode(data);
Assert.IsTrue(result == "C6BD2686D765C25433A11810493987BD");
}
示例6: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
string user=Request.QueryString["user"].ToString();
string pass = Request.QueryString["pass"].ToString();
MD5 EncodeMDS = new MD5();
DataSet ds = new DataSet();
UserManagerSystem UserManage = new UserManagerSystem();
ds=UserManage.GetUserAccount(user);
if (ds.Tables.Count > 0)
{
if (ds.Tables[0].Rows.Count > 0)
{
string PassUser = ds.Tables[0].Rows[0]["password"].ToString();
if (EncodeMDS.Verify(pass, PassUser))
{
isOk = "ok";
string[] userAcount = new string[3];
userAcount[0] = ds.Tables[0].Rows[0]["id"].ToString();
userAcount[1] = ds.Tables[0].Rows[0]["UserName"].ToString();
userAcount[2] = ds.Tables[0].Rows[0]["ContactName"].ToString();
Session["infoUser"] = userAcount;
}
}
}
}
catch (Exception ex)
{
Console.Write(ex.ToString());
}
Response.Write(isOk);
}
示例7: FileSystemProvider
public FileSystemProvider(string path = null)
{
this.md5 = MD5.Create();
this.binaryFormatter = new BinaryFormatter();
this.InitializeDirectories(path);
this.InitializeMetaData();
this.CheckHashes();
}
示例8: UploadFile
// upload
public async Task<InputFile> UploadFile(string filename, Stream stream, FileUploadProcessHandler handler) {
TLApi api = await session.GetFileSessionMain();
long fileId = Helpers.GenerateRandomLong();
MD5 hash = new MD5();
if(stream.Length < 128*1024) {
handler(0.0f);
byte[] data = new byte[stream.Length];
stream.Read(data, 0, (int) stream.Length);
bool result = await api.upload_saveFilePart(fileId, 0, data);
//while(result != true) {
// result = await api.upload_saveFilePart(fileId, 0, data);
//}
hash.Update(data);
handler(1.0f);
return TL.inputFile(fileId, 1, filename, hash.FinalString());
}
bool big = stream.Length > 10*1024*1024;
float allStreamLength = stream.Length;
int chunkSize = 128*1024;
int chunkCount = (int) (stream.Length/chunkSize);
int lastChunkSize = (int) (stream.Length - chunkSize*chunkCount);
int allChunksCount = chunkCount + (lastChunkSize != 0 ? 1 : 0);
for(int i = 0; i < chunkCount; i++) {
handler((float) i*(float) chunkSize/allStreamLength);
byte[] data = new byte[chunkSize];
stream.Read(data, 0, chunkSize);
bool result = big ? await api.upload_saveBigFilePart(fileId, i, allChunksCount, data) : await api.upload_saveFilePart(fileId, i, data);
//while(result != true) {
// result = await api.upload_saveFilePart(fileId, i, data);
//}
hash.Update(data);
}
if(lastChunkSize != 0) {
handler((float) chunkCount*(float) chunkSize/allStreamLength);
byte[] lastChunkData = new byte[lastChunkSize];
stream.Read(lastChunkData, 0, lastChunkSize);
bool lastChunkResult = big ? await api.upload_saveBigFilePart(fileId, chunkCount, allChunksCount, lastChunkData) : await api.upload_saveFilePart(fileId, chunkCount, lastChunkData);
//while(lastChunkResult != true) {
// lastChunkResult = await api.upload_saveFilePart(fileId, chunkCount, lastChunkData);
//}
hash.Update(lastChunkData);
}
handler(1.0f);
return TL.inputFile(fileId, allChunksCount, filename, hash.FinalString());
}
示例9: CalcMd5Hash
public static string CalcMd5Hash(MD5 md5, string filePath)
{
byte[] hash;
using (var stream = new FileStream(filePath, FileMode.Open, FileAccess.Read))
{
hash = md5.ComputeHash(stream);
}
return BitConverter.ToString(hash).Replace("-", "");
}
示例10: GetMd5Hash
private string GetMd5Hash(MD5 md5Hash, Stream inputStream)
{
byte[] data = md5Hash.ComputeHash(inputStream);
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
}
示例11: GetHash
public static string GetHash(MD5 crypto, string value)
{
byte[] hashByte = crypto.ComputeHash(Encoding.UTF8.GetBytes(value));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < hashByte.Length; i++)
{
sBuilder.Append(hashByte[i].ToString("x2"));
}
return sBuilder.ToString();
}
示例12: CreateFileStream
public override Stream CreateFileStream(string uploadFileName)
{
UploadFileName = uploadFileName;
FileStream stream = new FileStream(m_TempFilePath, FileMode.CreateNew);
m_UploadFileMD5 = MD5CryptoServiceProvider.Create();
return new CryptoStream(stream, m_UploadFileMD5, CryptoStreamMode.Write);
}
示例13: VerifyMd5Hash
// Verify a hash against a string.
public static bool VerifyMd5Hash(MD5 md5Hash, string src, string hash)
{
// Hash the input.
string hashOfInput = GetMd5Hash(md5Hash, src);
// Create a StringComparer an compare the hashes.
StringComparer comparer = StringComparer.OrdinalIgnoreCase;
return 0 == comparer.Compare(hashOfInput, hash);
}
示例14: GetMd5Hash
public static string GetMd5Hash(MD5 md5Hash, string input)
{
byte[] data = md5Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
StringBuilder sBuilder = new StringBuilder();
for (int i = 0; i < data.Length; i++)
{
sBuilder.Append(data[i].ToString("x2"));
}
return sBuilder.ToString();
}
示例15: GetHash
public static string GetHash(MD5 hash, string input)
{
StringBuilder result = new StringBuilder();
byte[] data = hash.ComputeHash(Encoding.UTF8.GetBytes(input));
for (int i = 0; i < data.Length; i++)
{
result.Append(data[i].ToString("x2"));
}
return result.ToString();
}