asp.net 对中文汉字的加密与解密代码
程序员文章站
2024-03-11 19:00:13
复制代码 代码如下:protected void page_load(object sender, eventargs e) { //加密算法 string usernam...
复制代码 代码如下:
protected void page_load(object sender, eventargs e)
{
//加密算法
string username = "我是陈建勇";
//md5加密 - 得到32位加密数据,数据不好解密。过于复杂。
username =formsauthentication.hashpasswordforstoringinconfigfile(username, "md5");
//sha1加密 - 得到40位加密数据,数据不好解密。过于复杂。
string username1 = formsauthentication.hashpasswordforstoringinconfigfile(username, "sha1");
response.write(username+"<br>");
response.write(username1+"<br>");
//解密算法
//普通加密
string s = "我是陈建勇";
string encodestr = "";
byte[] bytes = system.text.encoding.getencoding(0).getbytes(s);
try
{
encodestr = convert.tobase64string(bytes);
response.write("aa");
}
catch
{
encodestr = s;
response.write("bb");
}
response.write(encodestr+"<br>");
//普通解密
string decodestr = "";
byte[] bytes1 = convert.frombase64string(encodestr);
try
{
decodestr = system.text.encoding.getencoding(0).getstring(bytes1);
response.write("cc");
}
catch
{
response.write("dd");
decodestr = encodestr;
}
response.write(decodestr+"<br>");
//普通加密
string myname = "陈建勇";
myname = system.web.httputility.urlencode(myname, system.text.encoding.utf8);
response.write(myname+"<br>");
//普通解密
myname = system.web.httputility.urldecode(myname, system.text.encoding.utf8);
response.write(myname);
}
上一篇: k8s中configMap配置