国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

asp.net 字符串加密解密技術

2024-07-10 12:53:26
字體:
來源:轉載
供稿:網友

眾所周知,應用程序中的數據庫操作需要連接字符串,但如果沒有連接字符串,則無法完成一系列數據庫操作,下文是錯新技術頻道asp.net 字符串加密解密技術的介紹,希望可以幫助到有需要的你們。

復制代碼 代碼如下:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace www
{
public partial class jiami : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Bind();
}
private void Bind()
{
//加密
this.Title = DesEncrypt("pwd", "abcd1234");
this.Title += DesDecrypt(this.Title, "abcd1234");
Response.Write(DesDecrypt("2ikCw0TqKGo=", "abcd1234"));
}
///

/// 加密字符串
/// 注意:密鑰必須為8位
///


///字符串
///密鑰
///返回加密后的字符串
public string DesEncrypt(string inputString, string encryptKey)
{
byte[] byKey = null;
byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(encryptKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
byte[] inputByteArray = Encoding.UTF8.GetBytes(inputString);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
return Convert.ToBase64String(ms.ToArray());
}
catch (System.Exception error)
{
//return error.Message;
return null;
}
}
///


/// 解密字符串
///


///加了密的字符串
///密鑰
///返回解密后的字符串
public string DesDecrypt(string inputString, string decryptKey)
{
byte[] byKey = null;
byte[] IV = { 0x12, 0x34, 0x56, 0x78, 0x90, 0xAB, 0xCD, 0xEF };
byte[] inputByteArray = new Byte[inputString.Length];
try
{
byKey = System.Text.Encoding.UTF8.GetBytes(decryptKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
inputByteArray = Convert.FromBase64String(inputString);
MemoryStream ms = new MemoryStream();
CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(byKey, IV), CryptoStreamMode.Write);
cs.Write(inputByteArray, 0, inputByteArray.Length);
cs.FlushFinalBlock();
System.Text.Encoding encoding = new System.Text.UTF8Encoding();
return encoding.GetString(ms.ToArray());
}
catch (System.Exception error)
{
//return error.Message;
return null;
}
}
}
}

上文是關于asp.net 字符串加密解密技術,相信大家都有了一定的了解,想要了解更多的技術信息,請繼續關注錯新技術頻道吧!

?

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肥乡县| 金华市| 永仁县| 成武县| 佳木斯市| 苗栗市| 庆元县| 淄博市| 拉萨市| 惠水县| 晋中市| 永和县| 剑川县| 无为县| 牙克石市| 杭州市| 宝鸡市| 兴和县| 济源市| 泰州市| 增城市| 宜君县| 丹棱县| 镇坪县| 延津县| 南溪县| 广昌县| 太和县| 台东市| 瑞丽市| 永丰县| 衡东县| 南康市| 上思县| 松原市| 临湘市| 福鼎市| 滁州市| 福鼎市| 华池县| 柳河县|