本文整理汇总了C#中MD5CryptoServiceProvider类的典型用法代码示例。如果您正苦于以下问题:C# MD5CryptoServiceProvider类的具体用法?C# MD5CryptoServiceProvider怎么用?C# MD5CryptoServiceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MD5CryptoServiceProvider类属于命名空间,在下文中一共展示了MD5CryptoServiceProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetMd5Sum
public static string GetMd5Sum(string str)
{
// First we need to convert the string into bytes, which
// means using a text encoder.
Encoder enc = System.Text.Encoding.Unicode.GetEncoder();
// Create a buffer large enough to hold the string
byte[] unicodeText = new byte[str.Length * 2];
enc.GetBytes(str.ToCharArray(), 0, str.Length, unicodeText, 0, true);
// Now that we have a byte array we can ask the CSP to hash it
MD5 md5 = new MD5CryptoServiceProvider();
byte[] result = md5.ComputeHash(unicodeText);
// Build the final string by converting each byte
// into hex and appending it to a StringBuilder
StringBuilder sb = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
sb.Append(result[i].ToString("X2"));
}
// And return it
return sb.ToString();
}
开发者ID:ali-codehoppers,项目名称:simplicity-forms-estate-agent,代码行数:25,代码来源:Utility.cs
示例2: In
public void In(
[FriendlyName("Key", "The string to be used to generate the hash from.")]
string Key,
[FriendlyName("MD5 Hash", "The MD5 Hash generated by the Key.")]
out string Hash
)
{
if (Key != "")
{
UTF8Encoding ue = new UTF8Encoding();
byte[] bytes = ue.GetBytes(Key);
// encrypt bytes
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hashBytes = md5.ComputeHash(bytes);
// Convert the encrypted bytes back to a string (base 16)
string tmpHash = "";
for (int i = 0; i < hashBytes.Length; i++)
{
tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
}
Hash = tmpHash.PadLeft(32, '0');
}
else
{
uScriptDebug.Log("[Generate MD5 Hash] The Key provided was empty, returning an empty string for the MD5 Hash.", uScriptDebug.Type.Warning);
Hash = "";
}
}
开发者ID:Zyanede,项目名称:Own-Projects,代码行数:34,代码来源:uScriptAct_GenerateMD5Hash.cs
示例3: Encrypt
public string Encrypt(string ToEncrypt, bool useHasing)
{
byte[] keyArray;
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(ToEncrypt);
string Key = "malkit";
if (useHasing)
{
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(Key));
hashmd5.Clear();
}
else
{
keyArray = UTF8Encoding.UTF8.GetBytes(Key);
}
TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
tDes.Key = keyArray;
tDes.Mode = CipherMode.ECB;
tDes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tDes.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
tDes.Clear();
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
开发者ID:riteshventurepact,项目名称:TAPD,代码行数:25,代码来源:EncryptDecrypt.cs
示例4: Decrypt
public string Decrypt(string cypherString, bool useHasing)
{
byte[] keyArray;
byte[] toDecryptArray = Convert.FromBase64String(cypherString.Replace(' ','+'));
string key = "malkit";
if (useHasing)
{
MD5CryptoServiceProvider hashmd = new MD5CryptoServiceProvider();
keyArray = hashmd.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd.Clear();
}
else
{
keyArray = UTF8Encoding.UTF8.GetBytes(key);
}
TripleDESCryptoServiceProvider tDes = new TripleDESCryptoServiceProvider();
tDes.Key = keyArray;
tDes.Mode = CipherMode.ECB;
tDes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tDes.CreateDecryptor();
try
{
byte[] resultArray = cTransform.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length);
tDes.Clear();
return UTF8Encoding.UTF8.GetString(resultArray, 0, resultArray.Length);
}
catch (Exception ex)
{
throw ex;
}
}
开发者ID:riteshventurepact,项目名称:TAPD,代码行数:32,代码来源:EncryptDecrypt.cs
示例5: MD5Encode
/// <summary>
/// MD5加密
/// </summary>
/// <param name="strOriginal"></param>
/// <returns></returns>
public static string MD5Encode(string strOriginal)
{
byte[] byteInput = UTF8Encoding.UTF8.GetBytes(strOriginal);
MD5CryptoServiceProvider objMD5 = new MD5CryptoServiceProvider();
byte[] byteOutput = objMD5.ComputeHash(byteInput);
return BitConverter.ToString(byteOutput).Replace("-", "");
}
开发者ID:chutinhha,项目名称:fixed-asset-system,代码行数:12,代码来源:EncodeHelper.cs
示例6: ComputeMD5
public static string ComputeMD5(string value)
{
/*
* Create the md5 crypt service provider
*/
MD5 crypt = new MD5CryptoServiceProvider();
StreamWriter pwd = new StreamWriter(new MemoryStream());
pwd.Write(value);
pwd.Flush();
/*
* Compute the hash code
*/
pwd.BaseStream.Seek(0, SeekOrigin.Begin);
byte[] cryptHash = crypt.ComputeHash(pwd.BaseStream);
/*
* Convert the result to hex
*/
string result = "";
int nLen = cryptHash.Length;
for (int nPos = 0; nPos < nLen; nPos++)
{
byte cBuff = cryptHash[nPos];
result += Convert((long)cBuff, 16);
}
return result.ToLower();
}
开发者ID:kavallo,项目名称:E-Menu,代码行数:30,代码来源:MD5.cs
示例7: LogIn
protected void LogIn(object sender, EventArgs e)
{
// Colecting data
string email = TBEmail.Text;
string password = TBPass.Text;
// Hashing password
MD5 md5 = new MD5CryptoServiceProvider();
md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(password));
password = Convert.ToBase64String(md5.Hash);
// Checking login details
Staff account = DBConnectivity.login(email, password);
if (account != null)
{
// Loging OK
Session["auth_email"] = account.email;
Session["first_name"] = account.firstName;
Session["access"] = account.access;
Response.Redirect("~/Manage-Pets");
}
else
{
// Bad details
ErrorMessage.Visible = true;
FailureText.Text = "Bad credentials. Try again.";
}
}
开发者ID:knowbody,项目名称:fwp,代码行数:29,代码来源:Login.aspx.cs
示例8: Encrypt
public static string Encrypt(string toEncrypt, bool useHashing)
{
byte[] keyArray;
byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);
System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
string key = (string)settingsReader.GetValue("search", typeof(string));
if (useHashing)
{
MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
hashmd5.Clear();
}
else
keyArray = UTF8Encoding.UTF8.GetBytes(key);
TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
tdes.Key = keyArray;
tdes.Mode = CipherMode.ECB;
tdes.Padding = PaddingMode.PKCS7;
ICryptoTransform cTransform = tdes.CreateEncryptor();
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
tdes.Clear();
return Convert.ToBase64String(resultArray, 0, resultArray.Length);
}
开发者ID:gowrinath,项目名称:Public-Health-Care-System,代码行数:25,代码来源:encryption.cs
示例9: Decrypt
/// <summary>
/// Decrypt the given string using the specified key.
/// </summary>
/// <param name="strEncrypted">The string to be decrypted.</param>
/// <param name="strKey">The decryption key.</param>
/// <returns>The decrypted string.</returns>
public static string Decrypt(string strEncrypted, string strKey)
{
try
{
TripleDESCryptoServiceProvider objDESCrypto = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();
byte[] byteHash, byteBuff;
string strTempKey = strKey;
byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
objHashMD5 = null;
objDESCrypto.Key = byteHash;
objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB
byteBuff = Convert.FromBase64String(strEncrypted);
string strDecrypted = ASCIIEncoding.ASCII.GetString(objDESCrypto.CreateDecryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
objDESCrypto = null;
return strDecrypted;
}
catch (Exception ex)
{
return "Wrong Input. " + ex.Message;
}
}
开发者ID:Ndiya999,项目名称:Bulabula,代码行数:32,代码来源:SSTCryptographer.cs
示例10: In
public void In(
[FriendlyName("Key", "The string to be used to check against the provided MD5 hash.")]
string Key,
[FriendlyName("MD5 Hash", "The MD5 Hash to check the key against.")]
string Hash
)
{
if (Key != "" && Hash != "")
{
UTF8Encoding ue = new UTF8Encoding();
byte[] bytes = ue.GetBytes(Key);
// encrypt bytes
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hashBytes = md5.ComputeHash(bytes);
// Convert the encrypted bytes back to a string (base 16)
string tmpHash = "";
for (int i = 0; i < hashBytes.Length; i++)
{
tmpHash += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, '0');
}
string finalHash = tmpHash.PadLeft(32, '0');
if (finalHash == Hash)
{
m_GoodHash = true;
}
}
}
开发者ID:Oxy949,项目名称:Obscended,代码行数:33,代码来源:uScriptAct_CheckMD5Hash.cs
示例11: Encrypt
public static string Encrypt(string plainText )
{
string encrypted = null;
try
{
byte[] inputBytes = ASCIIEncoding.ASCII.GetBytes(plainText);
byte[] pwdhash = null;
MD5CryptoServiceProvider hashmd5;
//generate an MD5 hash from the password.
//a hash is a one way encryption meaning once you generate
//the hash, you cant derive the password back from it.
hashmd5 = new MD5CryptoServiceProvider();
pwdhash = hashmd5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(key));
hashmd5 = null;
// Create a new TripleDES service provider
TripleDESCryptoServiceProvider tdesProvider = new TripleDESCryptoServiceProvider();
tdesProvider.Key = pwdhash;
tdesProvider.Mode = CipherMode.ECB;
byte [] edata = tdesProvider.CreateEncryptor().TransformFinalBlock(inputBytes, 0, inputBytes.Length);
encrypted = Convert.ToBase64String( edata );
}
catch(Exception e)
{
string str = e.Message;
throw ;
}
return encrypted;
}
开发者ID:vibhutisuthar,项目名称:TEST,代码行数:31,代码来源:Tools.cs
示例12: md5method
public static string md5method(string textoPlano)
{
byte[] data = System.Text.UTF8Encoding.ASCII.GetBytes(textoPlano);
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hashbyte = md5.ComputeHash(data, 0, data.Length);
return BitConverter.ToString(hashbyte);
}
开发者ID:jaratj87,项目名称:grn,代码行数:7,代码来源:Default.aspx.cs
示例13: Com
private static string Com(Stream stream)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
md5.ComputeHash(stream);
byte[] hash = md5.Hash;
if (hash == null)
{
_ecode = MD5ErrorCode.E_ComputeHash;
return string.Empty;
}
StringBuilder sb = new StringBuilder();
foreach (byte byt in hash)
{
sb.Append(String.Format("{0:X1}", byt));
}
string ret = sb.ToString();
sb = null;
return ret;
}
开发者ID:seenen,项目名称:HerosTechBak_Seenen,代码行数:31,代码来源:MD5.cs
示例14: MD5
public static string MD5(string text)
{
string md5Hash;
StringBuilder sb;
byte[] textBytes;
byte[] encodedBytes;
MD5CryptoServiceProvider md5Provider;
if (text == null) {
throw new ArgumentNullException("text");
}
sb = new StringBuilder();
md5Provider = new MD5CryptoServiceProvider();
textBytes = ASCIIEncoding.Default.GetBytes(text);
encodedBytes = md5Provider.ComputeHash(textBytes);
for (int i = 0; i < encodedBytes.Length; i++) {
sb.AppendFormat("{0:x2}", encodedBytes[i]);
}
md5Hash = sb.ToString();
return md5Hash;
}
开发者ID:gerc,项目名称:CloudPay,代码行数:25,代码来源:Cryptography.cs
示例15: HMACMD5
public HMACMD5 (byte[] key) {
m_hashName = "MD5";
m_hash1 = new MD5CryptoServiceProvider();
m_hash2 = new MD5CryptoServiceProvider();
HashSizeValue = 128;
base.InitializeKey(key);
}
开发者ID:sjyanxin,项目名称:WPFSource,代码行数:7,代码来源:HMACMD5.cs
示例16: GoodieTwoShoes
public static string GoodieTwoShoes(string factora)
{
MD5 md5 = new MD5CryptoServiceProvider();
string sResult = "";
string sSecret = "jsdkfjks3423345879(*&*&&fdsdf903e38278sd";
string sStringIn = factora + sSecret;
char[] caData = sStringIn.ToCharArray();
byte[] data = new byte[caData.GetLength(0)];
int i = 0;
foreach (char c in caData)
{
data[i++] = (byte)c;
}
byte[] result = md5.ComputeHash(data);
string sTemp;
foreach (byte b in result)
{
sTemp = b.ToString("x");
if (sTemp.Length == 1)
{
sTemp = "0" + sTemp;
}
sResult = sResult + sTemp;
}
char[] szNum = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
sResult = string.Format("{0}-{1}-{2}-{3}", sResult.Substring(3, 5), sResult.Substring(8, 5), sResult.Substring(16, 5), sResult.Substring(22, 5));
return sResult.ToUpper();
}
开发者ID:spamarti,项目名称:wwt-web-client,代码行数:35,代码来源:login.aspx.cs
示例17: Initialize
/// <summary>
/// Initializes the telemetry client.
/// </summary>
public static void Initialize(IServiceProvider serviceProvider, string version, string telemetryKey)
{
if (_telemetry != null)
throw new NotSupportedException("The telemetry client is already initialized");
var dte = (DTE2)serviceProvider.GetService(typeof(DTE));
_telemetry = new TelemetryClient();
_telemetry.Context.Session.Id = Guid.NewGuid().ToString();
_telemetry.Context.Device.Model = dte.Edition;
_telemetry.InstrumentationKey = telemetryKey;
_telemetry.Context.Component.Version = version;
byte[] enc = Encoding.UTF8.GetBytes(Environment.UserName + Environment.MachineName);
using (var crypto = new MD5CryptoServiceProvider())
{
byte[] hash = crypto.ComputeHash(enc);
_telemetry.Context.User.Id = Convert.ToBase64String(hash);
}
_events = dte.Events.DTEEvents;
_events.OnBeginShutdown += delegate { _telemetry.Flush(); };
Enabled = true;
}
开发者ID:modulexcite,项目名称:MicrosoftBandTools,代码行数:28,代码来源:Telemetry.cs
示例18: btConfirm_Click
/// <summary>
/// 处理确定按钮点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btConfirm_Click(object sender, EventArgs e)
{
Admin admin = new Admin();
MD5CryptoServiceProvider HashMD5 = new MD5CryptoServiceProvider();
string oldPwd =
ASCIIEncoding.ASCII.GetString(HashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(tbOldPwd.Text)));
string newPwd1 =
ASCIIEncoding.ASCII.GetString(HashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(tbNewPwd1.Text)));
string newPwd2 =
ASCIIEncoding.ASCII.GetString(HashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(tdNewPwd2.Text)));
if (admin.ChangePassword(Session["UserName"].ToString(), oldPwd, newPwd1, newPwd2))
{
//胡媛媛修改,修改跳转语句的位置,2010-01-15
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert",
"<script>alert('修改成功!');window.location='./index.aspx'</script>");
//Response.Redirect("./index.aspx");
//胡媛媛修改,修改跳转语句的位置,2010-01-15
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert",
"<script>alert('对不起,您修改密码失败,原因可能是您输入的原密码不正确或是两次输入的新密码不一致!')</script>");
}
}
开发者ID:dalinhuang,项目名称:my-project-step,代码行数:31,代码来源:Change_Admin_Password.aspx.cs
示例19: BAddStaff_Click
// Handling adding new staff member button click
protected void BAddStaff_Click(object sender, EventArgs e)
{
// Collecting data
String pass = TBPassword.Text;
String passRep = TBPasswordRep.Text;
String email = TBEmail.Text;
// Checking email is unique
if (!DBConnectivity.checkEmailUnique(email))
{
displayErrorMessage("Member with this email is already registered.");
return;
}
// Checking passwords are same
if (pass != passRep)
{
displayErrorMessage("Passwords are not the same. Please try again.");
return;
}
// Checking if access level was selected
if (DDLAccess.SelectedValue == "0")
{
displayErrorMessage("Please select access level.");
return;
}
// Hashing password
MD5 md5 = new MD5CryptoServiceProvider();
md5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(pass));
pass = Convert.ToBase64String(md5.Hash);
// Collecting data
string[,] staffData = new string[5, 2] {
{ "first_name", TBFirstName.Text },
{ "last_name", TBLastName.Text },
{ "email", email },
{ "password", pass },
{ "access", DDLAccess.SelectedValue },
};
// Adding new spieces to database
Boolean added = DBConnectivity.addStaff(staffData);
// Checking if record was added
if (added)
{
displaySuccessMessage("Staff member was added successfully");
// Reloading GridView
loadGridLast();
}
else
{
displayErrorMessage("Error adding member. Please try again.");
}
// Reseting form
resetForm();
}
开发者ID:knowbody,项目名称:fwp,代码行数:61,代码来源:Manage-Staff.aspx.cs
示例20: GetMd5Values
public static Dictionary<string, string> GetMd5Values(string platformPath)
{
var dicFileMd5 = new Dictionary<string, string>();
var md5Generator = new MD5CryptoServiceProvider();
//var dir = Path.Combine(Application.dataPath, "AssetBundle/" + platform);
foreach (var filePath in Directory.GetFiles(platformPath))
{
if (filePath.Contains(".meta") || filePath.Contains("VersionMD5") || filePath.Contains(".xml"))
{
continue;
}
var file = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
var hash = md5Generator.ComputeHash(file);
var strMd5 = System.BitConverter.ToString(hash);
file.Close();
string key = filePath.Substring(platformPath.Length, filePath.Length - platformPath.Length);
if (dicFileMd5.ContainsKey(key) == false)
dicFileMd5.Add(key, strMd5);
else
Debug.LogWarning("<Two File has the same name> name = " + filePath);
}
return dicFileMd5;
}
开发者ID:wuxin0602,项目名称:Nothing,代码行数:26,代码来源:GenerateVersionNum.cs
注:本文中的MD5CryptoServiceProvider类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论