本文整理汇总了C#中System.Security.Cryptography.MD5CryptoServiceProvider类的典型用法代码示例。如果您正苦于以下问题:C# MD5CryptoServiceProvider类的具体用法?C# MD5CryptoServiceProvider怎么用?C# MD5CryptoServiceProvider使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MD5CryptoServiceProvider类属于System.Security.Cryptography命名空间,在下文中一共展示了MD5CryptoServiceProvider类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: MD5
public static String MD5(String text)
{
UTF8Encoding encoder = new UTF8Encoding();
var md5 = new MD5CryptoServiceProvider();
byte[] hashedDataBytes = md5.ComputeHash(encoder.GetBytes(text));
return System.Convert.ToBase64String(hashedDataBytes);
}
开发者ID:codaxy,项目名称:common,代码行数:7,代码来源:Cryptography.cs
示例2: GetMd5Sum
// Create an md5 sum string of this string
public static string GetMd5Sum(this 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
var sb = new StringBuilder();
for (int i = 0; i < result.Length; i++)
{
sb.Append(result[i].ToString("X2"));
}
// And return it
return sb.ToString();
}
开发者ID:jcoxhead,项目名称:SilverlightExamples,代码行数:26,代码来源:Md5Sum.cs
示例3: GetHash
/// <summary>
/// Gets the hash.
/// </summary>
/// <param name="data">The data.</param>
/// <returns></returns>
public static string GetHash(byte[] data)
{
// This is one implementation of the abstract class MD5.
MD5 md5 = new MD5CryptoServiceProvider();
return BitConverter.ToString(md5.ComputeHash(data)).Replace("-", String.Empty);
}
开发者ID:kouweizhong,项目名称:ajaxnet,代码行数:12,代码来源:MD5Helper.cs
示例4: GuardarAdministrativo
public void GuardarAdministrativo(String username, String password)
{
MD5CryptoServiceProvider provider = new MD5CryptoServiceProvider();
byte[] data = System.Text.Encoding.ASCII.GetBytes(password);
data = provider.ComputeHash(data);
string md5 = string.Empty;
for (int i = 0; i < data.Length; i++)
{
md5 += data[i].ToString("x2").ToLower();
}
password = md5;
var sql = new StringBuilder();
sql.AppendLine("insert into administradores (admin_username,admin_password) values (@username,@password)");
var parametros = new List<SqlParameter>
{
new SqlParameter
{
ParameterName = "username",
SqlDbType =SqlDbType.VarChar,
SqlValue = username
},
new SqlParameter
{
ParameterName = "password",
SqlDbType = SqlDbType.VarChar,
SqlValue = password
},
};
AccesoDatosSQL.Instance.Accesar.EjecutarConsultaSQL(sql.ToString(), parametros);
if (AccesoDatosSQL.Instance.Accesar.HayError)
{
this.IsError = AccesoDatosSQL.Instance.Accesar.HayError;
this.ErrorDescripcion = AccesoDatosSQL.Instance.Accesar.ErrorDescripcion;
}
}
开发者ID:LightProgrammingCompany,项目名称:EtzJaimClinic,代码行数:35,代码来源:AdministradoresSQL.cs
示例5: EncryptString
/// <summary>
/// Returnes the string as MD5 hashing
/// </summary>
/// <param name="datastr"></param>
/// <returns></returns>
public static string EncryptString(string datastr)
{
HashAlgorithm mhash = new MD5CryptoServiceProvider();
string res = string.Empty; // the returning result
// Convert the original string to array of Bytes
byte[] bytValue = Encoding.UTF8.GetBytes(datastr);
// Compute the Hash, returns an array of Bytes
byte[] bytHash = mhash.ComputeHash(bytValue);
mhash.Clear();
// convert the byte data to hex string values
for (int i = 0; i < bytHash.Length; i++)
{
if (bytHash[i] < 16)
{
res += "0" + bytHash[i].ToString("x");
}
else
{
res += bytHash[i].ToString("x");
}
}
return res;
}
开发者ID:HydAu,项目名称:sitecore8ecommerce,代码行数:33,代码来源:Hashing.cs
示例6: MD5Bytes
/// <summary>
/// MD5加密 返回纯字节
/// </summary>
/// <param name="k"></param>
/// <returns></returns>
public static byte[] MD5Bytes(string sourceString)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] keyBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(sourceString));
md5.Clear();
return keyBytes;
}
开发者ID:jameyK,项目名称:Sophia.WeChat,代码行数:12,代码来源:MD5Encrypt.cs
示例7: Decrypt
internal string Decrypt(string value)
{
MD5CryptoServiceProvider hashProvider = null;
TripleDESCryptoServiceProvider provider = null;
try
{
hashProvider = new MD5CryptoServiceProvider();
var hashPassPhrase = hashProvider.ComputeHash(Encoding.UTF8.GetBytes(passPhrase));
provider = new TripleDESCryptoServiceProvider();
provider.Key = hashPassPhrase;
provider.Mode = CipherMode.ECB;
provider.Padding = PaddingMode.PKCS7;
var dataToEncrypt = Convert.FromBase64String(value);
var decryptor = provider.CreateDecryptor();
var results = decryptor.TransformFinalBlock(dataToEncrypt, 0, dataToEncrypt.Length);
return Encoding.UTF8.GetString(results);
}
finally
{
if (provider != null) provider.Clear();
if (hashProvider != null) hashProvider.Clear();
}
}
开发者ID:amido,项目名称:Amido.PreProcessor,代码行数:27,代码来源:MD5.cs
示例8: GetMd5_16
/// <summary>
/// 16位加密
/// </summary>
/// <param name="ConvertString"></param>
/// <returns></returns>
public static string GetMd5_16(string ConvertString)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
t2 = t2.Replace("-", "");
return t2;
}
开发者ID:nick121212,项目名称:xima_desktop3,代码行数:12,代码来源:MD5Until.cs
示例9: CreateSign
/// <summary>
/// 创建签名
/// </summary>
/// <param name="text">明文</param>
/// <param name="merchantKey">商户密钥</param>
/// <returns>签名</returns>
public static string CreateSign(string text, string merchantKey)
{
MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
byte[] hashBytes = md5.ComputeHash(Encoding.UTF8.GetBytes(text + "&Key=" + merchantKey));
return BitConverter.ToString(hashBytes).Replace("-", "").ToUpper();
}
开发者ID:PersonalTeam,项目名称:cn.memeda.weixinapp,代码行数:13,代码来源:SecurityUtil.cs
示例10: Md5Encrypt
/// <summary>
/// 用MD5算法对字符串加密
/// </summary>
/// <param name="strOriginal"></param>
/// <returns></returns>
public static byte[] Md5Encrypt(string strOriginal)
{
var encoder = new UTF8Encoding();
var md5Hasher = new MD5CryptoServiceProvider();
byte[] bytePassword = md5Hasher.ComputeHash(encoder.GetBytes(strOriginal));
return bytePassword;
}
开发者ID:zhouyongtao,项目名称:TicketHelper,代码行数:12,代码来源:MD5Encrypt.cs
示例11: Decrypt
/// <summary>
/// Decrypt the given string using the specified key.
/// </summary>
/// <param name="strEncrypted">The string to be decrypted.</param>
/// <param name="key">The decryption key.</param>
/// <returns>The decrypted string.</returns>
/// <exception cref="Exception">Unexpected Exception</exception>
public static string Decrypt(string strEncrypted, string key)
{
try
{
TripleDESCryptoServiceProvider decrypto = new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider hash = new MD5CryptoServiceProvider();
byte[] byteHash, byteBuff;
string tempKey = key;
byteHash = hash.ComputeHash(ASCIIEncoding.ASCII.GetBytes(tempKey));
hash = null;
decrypto.Key = byteHash;
decrypto.Mode = CipherMode.ECB; //CBC, CFB
byteBuff = Convert.FromBase64String(strEncrypted);
string strDecrypted = ASCIIEncoding.ASCII.GetString(decrypto.CreateDecryptor().TransformFinalBlock(byteBuff, 0, byteBuff.Length));
decrypto = null;
return strDecrypted;
}
catch (Exception ex)
{
throw new Exception("Error: " + ex.Message + ".\n Decryption Failed. Please start over..!");
}
}
开发者ID:sameesh-s,项目名称:stego-app,代码行数:37,代码来源:Text.cs
示例12: AdminRegister
public JsonResult AdminRegister()
{
if (user.getAll().Count() == 0)
{
if (Request["Password"] == null)
{
return Json(new { info = false, message = "密码不能为空" });
}
if (Request["UserName"] == null)
{
return Json(new { info = false, message = "用户名不能为空" });
}
User u = new User();
MD5 md5 = new MD5CryptoServiceProvider();
byte[] mdpass = md5.ComputeHash(System.Text.Encoding.Default.GetBytes("password" + Request["Password"]));
u.Password = System.Text.Encoding.Default.GetString(mdpass);
u.UserName = Request["UserName"];
u.IsUse = true;
u.Role_Id = 1;
u.CreateTime = DateTime.Now;
try
{
user.addUser(u);
user.save();
}
catch
{
return Json(new { info = false, message = "出错了" });
}
return Json(new { info = true, message = "管理员账户创建成功" });
}
else return Json(new { info = false, message = "出错了" });
}
开发者ID:WangJingye,项目名称:TaskManage,代码行数:34,代码来源:UserController.cs
示例13: parse_packet
public static FilePiece parse_packet(byte[] packet)
{
if (packet.Length < 28){ // header isn't long enough
return null;
}
Int32 data_length = System.BitConverter.ToInt32(packet, 0);
if (data_length < 0){ // no data
return null;
}
Int64 piece_number = System.BitConverter.ToInt64(packet, 4);
if (piece_number < 0){ // can't have less than 0 piece number
return null;
}
byte[] checksum = new byte[16];
for(int i = 12; i < 28; i++){
checksum[i] = packet[i];
}
System.ArraySegment<byte> data_segment = new System.ArraySegment<byte>(packet, 28, packet.Length-28);
byte[] data = data_segment.Array;
// do a checksum
MD5 check = new MD5CryptoServiceProvider();
byte[] sum = check.ComputeHash(data);
if (sum.Equals(checksum)){
return null; // data checksum doesn't match
}
FilePiece piece = new FilePiece(piece_number, data);
return piece;
}
开发者ID:windsurfer,项目名称:C-Sharp-Multicast,代码行数:32,代码来源:FilePiece.cs
示例14: GameEncryption
private byte[] xorData; // This table is used for encrypting the server->client stream
#endregion Fields
#region Constructors
public GameEncryption(uint seed)
{
cipherTable = new byte[0x100];
// Set up the crypt key
byte[] key = new byte[16];
key[0] = key[4] = key[8] = key[12] = (byte)((seed >> 24) & 0xff);
key[1] = key[5] = key[9] = key[13] = (byte)((seed >> 16) & 0xff);
key[2] = key[6] = key[10] = key[14] = (byte)((seed >> 8) & 0xff);
key[3] = key[7] = key[11] = key[15] = (byte)(seed & 0xff);
byte[] iv = new byte[0];
engine = new TwofishEncryption(128, ref key, ref iv, CipherMode.ECB, TwofishBase.EncryptionDirection.Decrypting);
// Initialize table
for ( int i = 0; i < 256; ++i )
cipherTable[i] = (byte)i;
sendPos = 0;
// We need to fill the table initially to calculate the MD5 hash of it
refreshCipherTable();
// Create a MD5 hash of the twofish crypt data and use it as a 16-byte xor table
// for encrypting the server->client stream.
MD5 md5 = new MD5CryptoServiceProvider();
xorData = md5.ComputeHash(cipherTable);
}
开发者ID:BackupTheBerlios,项目名称:sunuo-svn,代码行数:34,代码来源:GameEncryption.cs
示例15: Decrypt
public static string Decrypt(string cypherString, bool useHasing)
{
byte[] keyArray;
byte[] toDecryptArray = Convert.FromBase64String(cypherString);
string key = "uzma";
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:uzmaha,项目名称:Development-GitHub,代码行数:31,代码来源:CryptorEngine.cs
示例16: Encrypt
/// <summary>
/// Encrypts to provided string parameter.
/// </summary>
public static string Encrypt(string s)
{
if (s == null || s.Length == 0) return string.Empty;
string result = string.Empty;
try
{
byte[] buffer = Encoding.ASCII.GetBytes(s);
TripleDESCryptoServiceProvider des =
new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider MD5 =
new MD5CryptoServiceProvider();
des.Key =
MD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(cryptoKey));
des.IV = IV;
result = Convert.ToBase64String(
des.CreateEncryptor().TransformFinalBlock(
buffer, 0, buffer.Length));
}
catch
{
throw;
}
return result;
}
开发者ID:nageshverma2003,项目名称:TrackProtectSource,代码行数:34,代码来源:EncryptionClass.cs
示例17: GetMD5
// Creates an MD5 hash of input
public static string GetMD5(string s)
{
MD5 md5 = new MD5CryptoServiceProvider ();
Byte[] bytes = ASCIIEncoding.Default.GetBytes (s);
Byte[] encodedBytes = md5.ComputeHash (bytes);
return BitConverter.ToString (encodedBytes).ToLower ().Replace ("-", "");
}
开发者ID:forkmerge,项目名称:SparkleShare,代码行数:8,代码来源:SparkleUIHelpers.cs
示例18: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
WxConfig = EasyWeixin.CommonAPIs.CommonApi.GetWxConfigResult(appid, appsecert, Request.Url.ToString());
QRCodeEncoder encoder = new QRCodeEncoder();
Bitmap bt = encoder.Encode(Request.Url.ToString());
var md5 = new MD5CryptoServiceProvider();
var start = Encoding.Default.GetBytes(Request.Url.ToString());
byte[] output = md5.ComputeHash(start);
var result = BitConverter.ToString(output).Replace("-", "");
var direName = "~/tmpQrImg/";
var filename = direName + result + ".png";
var filepath = Server.MapPath(filename);
if (!Directory.Exists(direName))
{
Directory.CreateDirectory(direName);
}
if (!File.Exists(filename))
{
bt.Save(filename, ImageFormat.Png);
}
ImgSrc = filename;
}
}
开发者ID:the404,项目名称:xyz,代码行数:29,代码来源:Scan.aspx.cs
示例19: GetListHash
public static string GetListHash(IEnumerable<string> hashes)
{
if (hashes == null)
throw new ArgumentNullException("hashes");
string result;
try
{
using (var s = new StreamWriter(new MemoryStream()))
{
foreach (var hash in hashes)
s.Write(hash);
s.Flush();
var bs = s.BaseStream;
bs.Position = 0;
using (var md5 = new MD5CryptoServiceProvider())
{
md5.ComputeHash(bs);
result = string.Join("", md5.Hash.Select(x => string.Format("{0:X2}", x)).ToArray());
}
}
}
catch (Exception x)
{
throw new ApplicationException(string.Format("Could not hash the list of {0} strings: {1}", hashes.Count(), x.Message), x);
}
return result;
}
开发者ID:skw0rm,项目名称:Xtall,代码行数:28,代码来源:ManifestManager.cs
示例20: Decrypt
public static string Decrypt(string cipherText, string passPhrase)
{
try
{
TripleDESCryptoServiceProvider objDESCrypto =
new TripleDESCryptoServiceProvider();
MD5CryptoServiceProvider objHashMD5 = new MD5CryptoServiceProvider();
byte[] byteHash, byteBuff;
string strTempKey = passPhrase;
byteHash = objHashMD5.ComputeHash(ASCIIEncoding.ASCII.GetBytes(strTempKey));
objHashMD5 = null;
objDESCrypto.Key = byteHash;
objDESCrypto.Mode = CipherMode.ECB; //CBC, CFB
byteBuff = Convert.FromBase64String(cipherText);
string strDecrypted = ASCIIEncoding.ASCII.GetString
(objDESCrypto.CreateDecryptor().TransformFinalBlock
(byteBuff, 0, byteBuff.Length));
objDESCrypto = null;
return strDecrypted;
}
catch (Exception ex)
{
return null;
}
}
开发者ID:TokleMahesh,项目名称:BG,代码行数:25,代码来源:StringCipher.cs
注:本文中的System.Security.Cryptography.MD5CryptoServiceProvider类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论