找传奇、传世资源到传世资源站!

全角半角转换/md5加密 等示例源码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

全角半角转换/md5加密 等示例源码 C#语言基础-第1张

using System;using System.Collections.Generic;using System.Linq;using System.Security.Cryptography;using System.Text;using System.Threading.Tasks;using System.Web.Security;namespace ConsoleApplication1{public static class Clas{public static string MD5 (this string text){return FormsAuthentication.HashPasswordForStoringInConfigFile (text, "md5");} [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBeCasedCorrectly", MessageId = "SHA")] public static string SHA1 (this string text){return FormsAuthentication.HashPasswordForStoringInConfigFile (text, "sha1");}public static string GetMD5_32(string s, string _input_charset){MD5 md5 = new MD5CryptoServiceProvider();byte[] t = md5.ComputeHash(Encoding.GetEncoding(_input_charset).GetBytes(s));StringBuilder sb = new StringBuilder(32);for (int i = 0; i < t.Length; i ){sb.Append(t[i].ToString("x").PadLeft(2, '0'));}return sb.ToString();}static string myMD5(string str){string pwd = "";MD5 md5 = new MD5CryptoServiceProvider();Byte[] byt = md5.ComputeHash(Encoding.Unicode.GetBytes(str));for (int i = 0; i < byt.Length; i ){pwd = byt[i].ToString("x");}return pwd;}/// <summary>/// MD5 加密(不可逆加密)/// </summary>/// <param name="pass">要加密的原始字串</param>/// <returns></returns> public static string MD5Encrypt(string pass){System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();byte[] bytResult = md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(pass));md5.Clear();string strResult = BitConverter.ToString(bytResult);strResult = strResult.Replace("-", "");return strResult;}public static void Example(string userInput){string sbc = userInput.ToSBC(); //转全角//具体操作,如存入数据库 string dbc = userInput.ToDBC();//转半角//具体操作,如存入数据库 }/// <summary>/// 转全角(SBC case)/// </summary>/// <param name="input">任意字符串</param>/// <returns>全角字符串</returns>public static string ToSBC(this string input){char[] c = input.ToCharArray();for (int i = 0; i < c.Length; i ){if (c[i] == 32){c[i] = (char)12288;continue;}if (c[i] < 127)c[i] = (char)(c[i] 65248);}return new string(c);}/// <summary>/// 转半角(DBC case)/// </summary>/// <param name="input">任意字符串</param>/// <returns>半角字符串</returns>public static string ToDBC(this string input){char[] c = input.ToCharArray();for (int i = 0; i < c.Length; i ){if (c[i] == 12288){c[i] = (char)32;continue;}if (c[i] > 65280 && c[i] < 65375)c[i] = (char)(c[i] - 65248);}return new string(c);}public static void Example2(string productName){string shortName = productName.GetChineseSpell();}/// <summary>/// 获取汉字拼音首字母/// </summary>/// <param name="s">输入</param>/// <returns>汉字拼音首字母,其它字符原样返回</returns>public static string GetChineseSpell(this string s){return null;//请自行完成}public static string cc(){return "adfadsf";}public static string cc(this string name){return name;}}}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复