本文整理汇总了C#中System.Security.Cryptography.MD5CryptoServiceProvider.TransformFinalBlock方法的典型用法代码示例。如果您正苦于以下问题:C# MD5CryptoServiceProvider.TransformFinalBlock方法的具体用法?C# MD5CryptoServiceProvider.TransformFinalBlock怎么用?C# MD5CryptoServiceProvider.TransformFinalBlock使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.MD5CryptoServiceProvider
的用法示例。
在下文中一共展示了MD5CryptoServiceProvider.TransformFinalBlock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: md5Hash
public static string md5Hash(this Bitmap bitmap)
{
try
{
if (bitmap.isNull())
return null;
//based on code snippets from http://dotnet.itags.org/dotnet-c-sharp/85838/
using (var strm = new MemoryStream())
{
var image = new Bitmap(bitmap);
bitmap.Save(strm, System.Drawing.Imaging.ImageFormat.Bmp);
strm.Seek(0, 0);
byte[] bytes = strm.ToArray();
var md5 = new MD5CryptoServiceProvider();
byte[] hashed = md5.TransformFinalBlock(bytes, 0, bytes.Length);
string hash = BitConverter.ToString(hashed).ToLower();
md5.Clear();
image.Dispose();
return hash;
}
}
catch (Exception ex)
{
ex.log("in bitmap.md5Hash");
return "";
}
}
示例2: CalcHash
public void CalcHash()
{
using (var hash = new MD5CryptoServiceProvider()) {
foreach (var xt in mXmitTaskList) {
hash.TransformBlock(xt.xmitData, 0, xt.xmitData.Length, xt.xmitData, 0);
}
hash.TransformFinalBlock(new byte[0], 0, 0);
mXmitDataHash = hash.Hash;
}
}
示例3: GetGravatarUrl
/// <summary>
/// Gets the image URL for the gravatar with the given email
/// </summary>
/// <param name="email">The gravatar email</param>
/// <param name="size">Optional size</param>
/// <returns>The image URL</returns>
public static string GetGravatarUrl(this UrlHelper helper, string email, int size = 0)
{
var input = UTF8Encoding.UTF8.GetBytes(email) ;
var crypto = new MD5CryptoServiceProvider() ;
var hash = Convert.ToBase64String(crypto.TransformFinalBlock(input, 0, input.Length)) ;
crypto.Clear() ;
return "http://www.gravatar.com/avatar/" + hash.ToLower() +
(size > 0 ? "?s=" + size : "") ;
}
示例4: encodePapPassword
public static byte[] encodePapPassword(byte[] userPassBytes,byte[] requestAuthenticator,string sharedSecret)
{
if (userPassBytes.Length > 128)
throw new InvalidOperationException("the PAP password cannot be greater than 128 bytes...");
byte[] encryptedPass = null;
if (userPassBytes.Length % 16 == 0) {
encryptedPass = new byte[userPassBytes.Length];
} else {
encryptedPass = new byte[((userPassBytes.Length / 16) * 16) + 16];
}
System.Array.Copy(userPassBytes, 0, encryptedPass, 0, userPassBytes.Length);
for(int i = userPassBytes.Length; i < encryptedPass.Length; i++) {
encryptedPass[i] = 0;
}
byte[] sharedSecretBytes = System.Text.Encoding.ASCII.GetBytes(sharedSecret);
System.Security.Cryptography.MD5 md5;
for (int chunk = 0; chunk < (encryptedPass.Length / 16); chunk++)
{
md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
md5.TransformBlock(sharedSecretBytes, 0, sharedSecretBytes.Length, sharedSecretBytes, 0);
if (chunk == 0)
md5.TransformFinalBlock(requestAuthenticator, 0, requestAuthenticator.Length);
else
md5.TransformFinalBlock(encryptedPass, (chunk - 1) * 16, 16);
byte[] hash = md5.Hash;
for (int i = 0; i < 16; i++){
int j = i + chunk*16;
encryptedPass[j] = (byte) (hash[i] ^ encryptedPass[j]);
}
}
return encryptedPass;
}
示例5: CalcHash
public byte[] CalcHash()
{
mRecvFragmentList = mRecvFragmentList.OrderBy(o => o.StartPos).ToList();
using (var hash = new MD5CryptoServiceProvider()) {
foreach (var f in mRecvFragmentList) {
hash.TransformBlock(f.Content, 0, f.Content.Length, f.Content, 0);
}
hash.TransformFinalBlock(new byte[0], 0, 0);
byte[] result = new byte[HASH_BYTES];
Array.Copy(hash.Hash, result, HASH_BYTES);
return result;
}
}
示例6: MD5File
/// <summary>
/// ���ļ�����MD5����
/// </summary>
/// <param name="filePath"></param>
public static void MD5File(string filePath)
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
int bufferSize = 1048576; // ����������1MB
byte[] buff = new byte[bufferSize];
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.Initialize();
long offset = 0;
while (offset < fs.Length)
{
long readSize = bufferSize;
if (offset + readSize > fs.Length)
{
readSize = fs.Length - offset;
}
fs.Read(buff, 0, Convert.ToInt32(readSize)); // ��ȡһ�����ݵ�������
if (offset + readSize < fs.Length) // �������һ��
{
md5.TransformBlock(buff, 0, Convert.ToInt32(readSize), buff, 0);
}
else // ���һ��
{
md5.TransformFinalBlock(buff, 0, Convert.ToInt32(readSize));
}
offset += bufferSize;
}
fs.Close();
byte[] result = md5.Hash;
md5.Clear();
StringBuilder sb = new StringBuilder(32);
for (int i = 0; i < result.Length; i++)
{
sb.Append(result[i].ToString("X2"));
}
Console.WriteLine(sb.ToString());
Console.ReadLine();
}
示例7: GenerateChallengeRespose
public static string GenerateChallengeRespose(string challengeToken, string productID, string productKey)
{
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
byte[] bMD5Bytes = Encoding.Default.GetBytes(challengeToken + productKey);
MD5.TransformFinalBlock(bMD5Bytes, 0, bMD5Bytes.Length);
string strMD5Hash = To_Hex(MD5.Hash);
ulong[] uMD5Ints = MD5_To_Int(strMD5Hash);
string strCHLID = challengeToken + productID;
strCHLID = strCHLID.PadRight(strCHLID.Length + (8 - (strCHLID.Length % 8)), '0');
ulong[] uCHLIDInts = CHLID_To_Int(strCHLID);
ulong uKey = Create_Key(uMD5Ints, uCHLIDInts);
ulong uPartOne = ulong.Parse(strMD5Hash.Substring(0, 16), NumberStyles.HexNumber);
ulong uPartTwo = ulong.Parse(strMD5Hash.Substring(16, 16), NumberStyles.HexNumber);
return String.Format("{0:x16}{1:x16}", uPartOne ^ uKey, uPartTwo ^ uKey);
}
示例8: getHash
public static string getHash(string name)
{
string md5Final;
int readsize = 64*1024;
long read = 0;
byte[] buffer = new byte[readsize*2];
MD5 md5 = new MD5CryptoServiceProvider();
using (var stream = new FileStream(name, FileMode.Open, FileAccess.Read))
{
read = stream.Read(buffer, 0, readsize);
stream.Seek(-readsize, SeekOrigin.End);
read += stream.Read(buffer, readsize, readsize);
md5.TransformFinalBlock(buffer, 0, buffer.Length);
md5Final = String.Join("", md5.Hash.Select(x => x.ToString("x2")));
}
return md5Final;
}
示例9: GetFileMd5
/// <summary>
/// 获取文件的MD5值
/// </summary>
/// <param name="fileName"> 文件名 </param>
/// <returns> 32位MD5 </returns>
public static string GetFileMd5(string fileName)
{
FileStream fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read);
const int bufferSize = 1024 * 1024;
byte[] buffer = new byte[bufferSize];
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.Initialize();
long offset = 0;
while (offset < fs.Length)
{
long readSize = bufferSize;
if (offset + readSize > fs.Length)
{
readSize = fs.Length - offset;
}
fs.Read(buffer, 0, (int)readSize);
if (offset + readSize < fs.Length)
{
md5.TransformBlock(buffer, 0, (int)readSize, buffer, 0);
}
else
{
md5.TransformFinalBlock(buffer, 0, (int)readSize);
}
offset += bufferSize;
}
fs.Close();
byte[] result = md5.Hash;
md5.Clear();
StringBuilder sb = new StringBuilder(32);
foreach (byte b in result)
{
sb.Append(b.ToString("X2"));
}
return sb.ToString();
}
示例10: CreateQRY
public static string CreateQRY(string strProductID, string strProductKey, string strCHLData)
{
// First generate an MD5 hash object
MD5CryptoServiceProvider MD5 = new MD5CryptoServiceProvider();
byte[] bMD5Bytes = Encoding.Default.GetBytes(strCHLData + strProductKey);
MD5.TransformFinalBlock(bMD5Bytes, 0, bMD5Bytes.Length);
// Once we are done with that we should create 4 integers from the MD5 hash
string strMD5Hash = To_Hex(MD5.Hash);
ulong[] uMD5Ints = MD5_To_Int(strMD5Hash);
// Create a new string from the ProdID and CHLData and padd with zero's, then convert it to ulongs :-)
string strCHLID = strCHLData + strProductID;
strCHLID = strCHLID.PadRight(strCHLID.Length + (8 - (strCHLID.Length % 8)), '0');
ulong[] uCHLIDInts = CHLID_To_Int(strCHLID);
// Then fetch the key from the two arrays
ulong uKey = Create_Key(uMD5Ints, uCHLIDInts);
// And finally create the new hash :-)
ulong uPartOne = ulong.Parse(strMD5Hash.Substring(0, 16), NumberStyles.HexNumber);
ulong uPartTwo = ulong.Parse(strMD5Hash.Substring(16, 16), NumberStyles.HexNumber);
return String.Format("{0:x16}{1:x16}", uPartOne ^ uKey, uPartTwo ^ uKey);
}
示例11: CRAM_MD5_
public static Byte[] CRAM_MD5_(String Token, String Login, String Password)
{
var token = Token. ToUTF8Bytes();
var password = Password.ToUTF8Bytes();
var ipad = new Byte[64];
var opad = new Byte[64];
var startIndex = 0;
var length = token.Length;
// see also: http://tools.ietf.org/html/rfc2195 - 2. Challenge-Response Authentication Mechanism (CRAM)
// http://tools.ietf.org/html/rfc2104 - 2. Definition of HMAC
#region Copy the password into inner/outer padding and XOR it accordingly
if (password.Length > ipad.Length)
{
var HashedPassword = new MD5CryptoServiceProvider().ComputeHash(password);
Array.Copy(HashedPassword, ipad, HashedPassword.Length);
Array.Copy(HashedPassword, opad, HashedPassword.Length);
}
else
{
Array.Copy(password, ipad, password.Length);
Array.Copy(password, opad, password.Length);
}
for (var i = 0; i < ipad.Length; i++) {
ipad[i] ^= 0x36;
opad[i] ^= 0x5c;
}
#endregion
#region Calculate the inner padding
byte[] digest;
using (var MD5 = new MD5CryptoServiceProvider())
{
MD5.TransformBlock (ipad, 0, ipad.Length, null, 0);
MD5.TransformFinalBlock(token, startIndex, length);
digest = MD5.Hash;
}
#endregion
#region Calculate the outer padding
// oPAD (will use iPAD digest!)
using (var MD5 = new MD5CryptoServiceProvider())
{
MD5.TransformBlock (opad, 0, opad.Length, null, 0);
MD5.TransformFinalBlock(digest, 0, digest.Length);
digest = MD5.Hash;
}
#endregion
// result := login[space]digest
return Login.ToUTF8Bytes().
Concat(new Byte[1] { 0x20 }).
Concat(digest.ToHexString().ToUTF8Bytes()).
ToArray();
}
示例12: ComputeMD5
protected static byte[] ComputeMD5(byte[] key, byte[] salt, int saltHashRounds = DefaultSaltHashRounds)
{
// TODO: Test that saltHashRounds >= 1
using (var md5 = new MD5CryptoServiceProvider())
{
// Hash key
md5.TransformBlock(key, 0, key.Length, null, 0);
// Hash salt (saltHashRounds-1) times
for(int i = 1; i < saltHashRounds; i++)
{
md5.TransformBlock(salt, 0, salt.Length, null, 0);
}
// Final salt hash iteration
md5.TransformFinalBlock(salt, 0, salt.Length);
return md5.Hash;
}
}
示例13: AnyscMD5
public static string AnyscMD5(string filepath, ProgressBar pBar, Label lab)
{
FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read, FileShare.Read);
int bufferSize = 1048576; // 缓冲区大小,1MB
byte[] buff = new byte[bufferSize];
double blockcount = Math.Ceiling(fs.Length / Convert.ToDouble(bufferSize));
if (pBar.InvokeRequired == true)
{
SetText LSetText = new SetText(DoSetText);
SetValue PSetValue = new SetValue(DoSetMax);
pBar.Invoke(PSetValue, new Object[] { pBar, Convert.ToInt32(blockcount) });
lab.Invoke(LSetText, new Object[] { lab, Convert.ToString(0) + "%" });
}
int i = 1;
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.Initialize();
long offset = 0;
while (offset < fs.Length)
{
long readSize = bufferSize;
if (offset + readSize > fs.Length)
{
readSize = fs.Length - offset;
}
fs.Read(buff, 0, Convert.ToInt32(readSize)); // 读取一段数据到缓冲区
if (offset + readSize < fs.Length) // 不是最后一块
{
md5.TransformBlock(buff, 0, Convert.ToInt32(readSize), buff, 0);
}
else // 最后一块
{
md5.TransformFinalBlock(buff, 0, Convert.ToInt32(readSize));
}
offset += bufferSize;
if (pBar.InvokeRequired == true)
{
SetValue PSetValue = new SetValue(DoSetValue);
SetText LSetText = new SetText(DoSetText);
pBar.Invoke(PSetValue, new Object[] { pBar, Convert.ToInt32(i) });
lab.Invoke(LSetText, new Object[] { lab, Convert.ToString(Math.Ceiling((double)(i / blockcount) * 100)) + "%" });
i++;
Application.DoEvents();
}
}
fs.Close();
byte[] result = md5.Hash;
md5.Clear();
StringBuilder sb = new StringBuilder(32);
for (int j = 0; j < result.Length; j++)
{
sb.Append(result[j].ToString("x2"));
}
return sb.ToString();
}
示例14: InitializeCipherSuite
public static CipherSuite InitializeCipherSuite(byte[] master, byte[] clientrnd, byte[] serverrnd, CipherDefinition definition, ConnectionEnd entity)
{
CipherSuite ret = new CipherSuite();
SymmetricAlgorithm bulk = (SymmetricAlgorithm)Activator.CreateInstance(definition.BulkCipherAlgorithm);
if (definition.BulkIVSize > 0)
bulk.Mode = CipherMode.CBC;
bulk.Padding = PaddingMode.None;
bulk.BlockSize = definition.BulkIVSize * 8;
// get the keys and IVs
byte[] client_mac, server_mac, client_key, server_key, client_iv, server_iv;
Ssl3DeriveBytes prf = new Ssl3DeriveBytes(master, clientrnd, serverrnd, false);
client_mac = prf.GetBytes(definition.HashSize);
server_mac = prf.GetBytes(definition.HashSize);
client_key = prf.GetBytes(definition.BulkKeySize);
server_key = prf.GetBytes(definition.BulkKeySize);
client_iv = prf.GetBytes(definition.BulkIVSize);
server_iv = prf.GetBytes(definition.BulkIVSize);
prf.Dispose();
if (definition.Exportable) { // make some extra modifications if the keys are exportable
MD5 md5 = new MD5CryptoServiceProvider();
md5.TransformBlock(client_key, 0, client_key.Length, client_key, 0);
md5.TransformBlock(clientrnd, 0, clientrnd.Length, clientrnd, 0);
md5.TransformFinalBlock(serverrnd, 0, serverrnd.Length);
client_key = new byte[definition.BulkExpandedSize];
Buffer.BlockCopy(md5.Hash, 0, client_key, 0, client_key.Length);
md5.Initialize();
md5.TransformBlock(server_key, 0, server_key.Length, server_key, 0);
md5.TransformBlock(serverrnd, 0, serverrnd.Length, serverrnd, 0);
md5.TransformFinalBlock(clientrnd, 0, clientrnd.Length);
server_key = new byte[definition.BulkExpandedSize];
Buffer.BlockCopy(md5.Hash, 0, server_key, 0, server_key.Length);
md5.Initialize();
md5.TransformBlock(clientrnd, 0, clientrnd.Length, clientrnd, 0);
md5.TransformFinalBlock(serverrnd, 0, serverrnd.Length);
client_iv = new byte[definition.BulkIVSize];
Buffer.BlockCopy(md5.Hash, 0, client_iv, 0, client_iv.Length);
md5.Initialize();
md5.TransformBlock(serverrnd, 0, serverrnd.Length, serverrnd, 0);
md5.TransformFinalBlock(clientrnd, 0, clientrnd.Length);
server_iv = new byte[definition.BulkIVSize];
Buffer.BlockCopy(md5.Hash, 0, server_iv, 0, server_iv.Length);
md5.Clear();
}
// generate the cipher objects
if (entity == ConnectionEnd.Client) {
ret.Encryptor = bulk.CreateEncryptor(client_key, client_iv);
ret.Decryptor = bulk.CreateDecryptor(server_key, server_iv);
ret.LocalHasher = new Ssl3RecordMAC(definition.HashAlgorithmType, client_mac);
ret.RemoteHasher = new Ssl3RecordMAC(definition.HashAlgorithmType, server_mac);
} else {
ret.Encryptor = bulk.CreateEncryptor(server_key, server_iv);
ret.Decryptor = bulk.CreateDecryptor(client_key, client_iv);
ret.LocalHasher = new Ssl3RecordMAC(definition.HashAlgorithmType, server_mac);
ret.RemoteHasher = new Ssl3RecordMAC(definition.HashAlgorithmType, client_mac);
}
// clear sensitive data
Array.Clear(client_mac, 0, client_mac.Length);
Array.Clear(server_mac, 0, server_mac.Length);
Array.Clear(client_key, 0, client_key.Length);
Array.Clear(server_key, 0, server_key.Length);
Array.Clear(client_iv, 0, client_iv.Length);
Array.Clear(server_iv, 0, server_iv.Length);
return ret;
}
示例15: Page_PreRender
protected void Page_PreRender(object sender, System.EventArgs e)
{
SharedBasePage requestPage = Page as SharedBasePage;
Control root = this;
HtmlGenericControl entry = new HtmlGenericControl("div");
if (SiteSecurity.GetUserByEmail(comment.AuthorEmail) == null)
{
entry.Attributes["class"] = "commentBoxStyle";
}
else
{
entry.Attributes["class"] = "commentBoxStyle commentBoxAuthorStyle";
}
root.Controls.Add(entry);
HtmlGenericControl entryTitle = new HtmlGenericControl("div");
entryTitle.Attributes["class"] = "commentDateStyle";
//Add the unique anchor for each comment
HtmlAnchor anchor = new HtmlAnchor();
anchor.Name = comment.EntryId;
entryTitle.Controls.Add(anchor);
if (requestPage.SiteConfig.AdjustDisplayTimeZone)
{
entryTitle.Controls.Add(new LiteralControl(requestPage.SiteConfig.GetConfiguredTimeZone().FormatAdjustedUniversalTime(comment.CreatedUtc)));
}
else
{
entryTitle.Controls.Add(new LiteralControl(comment.CreatedUtc.ToString("U") + " UTC"));
}
entry.Controls.Add(entryTitle);
HtmlGenericControl entryBody = new HtmlGenericControl("div");
if (SiteSecurity.GetUserByEmail(comment.AuthorEmail) == null)
{
entryBody.Attributes["class"] = "commentBodyStyle";
}
else
{
entryBody.Attributes["class"] = "commentBodyStyle commentBodyAuthorStyle";
}
if (comment.Content != null)
{
entryBody.Controls.Add(new LiteralControl(Regex.Replace(comment.Content, "\n", "<br />")));
}
if (!requestPage.HideAdminTools && SiteSecurity.IsInRole("admin"))
{
HtmlGenericControl spamStatus = new HtmlGenericControl("div");
spamStatus.Attributes["class"] = "commentSpamStateStyle";
spamStatus.InnerText = ApplicationResourceTable.GetSpamStateDescription(comment.SpamState);
entryBody.Controls.Add(spamStatus);
}
entry.Controls.Add(entryBody);
HtmlGenericControl footer = new HtmlGenericControl("div");
footer.Attributes["class"] = "commentBoxFooterStyle";
entry.Controls.Add(footer);
if (requestPage.SiteConfig.CommentsAllowGravatar && String.IsNullOrEmpty(comment.AuthorEmail) == false)
{
string hash = "";
byte[] data, enc;
data = Encoding.Default.GetBytes(comment.AuthorEmail.ToLowerInvariant());
using (MD5 md5 = new MD5CryptoServiceProvider())
{
enc = md5.TransformFinalBlock(data, 0, data.Length);
foreach (byte b in md5.Hash)
{
hash += Convert.ToString(b, 16).ToLower().PadLeft(2, '0');
}
md5.Clear();
}
string nogravpath = "";
if (requestPage.SiteConfig.CommentsGravatarNoImgPath != null)
{
if (requestPage.SiteConfig.CommentsGravatarNoImgPath != "")
{
if (requestPage.SiteConfig.CommentsGravatarNoImgPath.Substring(0, 4) == "http")
{
nogravpath = "&default=" + Server.UrlEncode(requestPage.SiteConfig.CommentsGravatarNoImgPath);
}
else
{
nogravpath = "&default=" + Server.UrlEncode(requestPage.SiteConfig.Root + requestPage.SiteConfig.CommentsGravatarNoImgPath);
}
}
}
if (String.IsNullOrEmpty(requestPage.SiteConfig.CommentsGravatarNoImgPath) == false)
{
//.........这里部分代码省略.........