vagabond的小站
我菜故我存在!!
博客园
::
首页
::
新随笔
::
联系
::
订阅
::
管理
::
13 随笔 :: 3 文章 :: 12 评论 :: 0 引用
关于在web.config里加密连接字符串.(开住金山词霸来翻译的.哈哈.)
..希望各位支持.呵呵.
前台代码:
<%
@ Page language
=
"
c#
"
Codebehind
=
"
EncryptingConnectionString.aspx.cs
"
AutoEventWireup
=
"
false
"
Inherits
=
"
NetTest.EncryptingConnectionString
"
%>
<!
DOCTYPE HTML PUBLIC
"
-//W3C//DTD HTML 4.0 Transitional//EN
"
>
<
HTML
>
<
HEAD
>
<
title
>
EncryptingConnectionString
</
title
>
<
meta name
=
"
GENERATOR
"
Content
=
"
Microsoft Visual Studio .NET 7.1
"
>
<
meta name
=
"
CODE_LANGUAGE
"
Content
=
"
C#
"
>
<
meta name
=
"
vs_defaultClientScript
"
content
=
"
JavaScript
"
>
<
meta name
=
"
vs_targetSchema
"
content
=
"
http://schemas.microsoft.com/intellisense/ie5
"
>
</
HEAD
>
<
body MS_POSITIONING
=
"
GridLayout
"
>
<
form id
=
"
Form1
"
method
=
"
post
"
runat
=
"
server
"
>
<
asp:Label id
=
"
Label1
"
style
=
"
Z-INDEX: 101; LEFT: 80px; POSITION: absolute; TOP: 96px
"
runat
=
"
server
"
>
Label
</
asp:Label
>
<
asp:Button id
=
"
Button1
"
style
=
"
Z-INDEX: 102; LEFT: 360px; POSITION: absolute; TOP: 152px
"
runat
=
"
server
"
Text
=
"
加密
"
></
asp:Button
>
<
asp:Label id
=
"
Label2
"
style
=
"
Z-INDEX: 103; LEFT: 224px; POSITION: absolute; TOP: 224px
"
runat
=
"
server
"
>
Label
</
asp:Label
>
<
asp:Button id
=
"
Button2
"
style
=
"
Z-INDEX: 104; LEFT: 512px; POSITION: absolute; TOP: 152px
"
runat
=
"
server
"
Text
=
"
解密
"
></
asp:Button
>
</
form
>
</
body
>
</
HTML
>
后台代码:
1
using
System;
2
using
System.Collections;
3
using
System.ComponentModel;
4
using
System.Data;
5
using
System.Drawing;
6
using
System.Web;
7
using
System.Web.SessionState;
8
using
System.Web.UI;
9
using
System.Web.UI.WebControls;
10
using
System.Web.UI.HtmlControls;
11
12
namespace
NetTest
13
{
14
/**/
///
<summary>
15
///
EncryptingConnectionString 的摘要说明。
16
///
</summary>
17
public
class
EncryptingConnectionString : System.Web.UI.Page
18
{
19
protected
System.Web.UI.WebControls.Label Label1;
20
21
private
void
Page_Load(
object
sender, System.EventArgs e)
22
{
23
//
在此处放置用户代码以初始化页面
24
}
25
//
加密连接字符串的方法
26
private
string
EncryptConnectionString(
string
connectionString)
27
{
28
29
Byte[] b
=
System.Text.ASCIIEncoding.ASCII.GetBytes(connectionString);
30
31
string
encryptedConnectionString
=
Convert.ToBase64String(b);
32
33
return
encryptedConnectionString;
34
}
35
36
protected
System.Web.UI.WebControls.Button Button1;
37
protected
System.Web.UI.WebControls.Label Label2;
38
protected
System.Web.UI.WebControls.Button Button2;
39
//
获得连接字符串
40
string
Connectionstring
=
System.Configuration.ConfigurationSettings.AppSettings[
"
ConnectStr
"
];
41
42
43
44
Web 窗体设计器生成的代码
#region
Web 窗体设计器生成的代码
45
override
protected
void
OnInit(EventArgs e)
46
{
47
//
48
//
CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
49
//
50
InitializeComponent();
51
base
.OnInit(e);
52
}
53
54
/**/
///
<summary>
55
///
设计器支持所需的方法 - 不要使用代码编辑器修改
56
///
此方法的内容。
57
///
</summary>
58
private
void
InitializeComponent()
59
{
60
this
.Button1.Click
+=
new
System.EventHandler(
this
.Button1_Click);
61
this
.Button2.Click
+=
new
System.EventHandler(
this
.Button2_Click);
62
this
.Load
+=
new
System.EventHandler(
this
.Page_Load);
63
64
}
65
#endregion
66
67
private
void
Button1_Click(
object
sender, System.EventArgs e)
68
{
69
Label1.Text
=
EncryptConnectionString(Connectionstring);
70
Session[
"
EncryptConnectionString
"
]
=
EncryptConnectionString(Connectionstring);
71
}
72
73
private
string
DecryptConnectionString(
string
EncryptConnectionString)
74
{
75
76
Byte[] b
=
Convert.FromBase64String(EncryptConnectionString);
77
78
string
decryptedConnectionString
=
System.Text.ASCIIEncoding.ASCII.GetString(b);
79
80
return
decryptedConnectionString;
81
82
}
83
84
private
void
Button2_Click(
object
sender, System.EventArgs e)
85
{
86
Label2.Text
=
DecryptConnectionString(Session[
"
EncryptConnectionString
"
].ToString());
87
Label1.Text
=
EncryptConnectionString(Connectionstring);
88
}
89
90
}
91
}
92
绿色通道:
好文要顶
关注我
收藏该文
与我联系
posted on 2005-08-13 12:36
vagabond VS net
阅读(1169)
评论(4)
编辑
收藏
评论
408463
#1楼
2005-08-17 09:18
非非.Net
哎。。。我的英语也烂。。。
哈哈
回复
引用
查看
#2楼
2005-08-29 14:44
沉默天蝎的.net学习汇集
hehe
支持下你
哈哈哈
你这个家伙也开始搞这个blog了
呵呵
回复
引用
查看
#3楼
[
楼主
]
2005-08-29 15:43
vagabond VS net
TO:沉默天蝎
3q
有空就来支持下.呵呵.
回复
引用
查看
#4楼
2006-05-24 23:34
三月
呵呵
这个不叫加密
叫字符转换~~
谢谢拉
我学到了一些东西^_^
回复
引用
查看
注册用户登录后才能发表评论,请
登录
或
注册
,
返回博客园首页
。
首页
博问
闪存
新闻
园子
招聘
知识库
最新IT新闻
:
·
TomTom导航仪被用于设置保险费率
·
传原淘宝总裁孙彤宇重回阿里 或被委以重任
·
谷歌微软苹果致信管制者:不滥用专利搞垄断
·
纽约时报:微软零售店毗邻苹果店属明智之举
·
网龙向91公司员工发放共计298万股奖励股份
»
更多新闻...
最新知识库文章
:
·
高级编程语言的发展历程
·
如何学习一门新的编程语言?
·
学习不同编程语言的重要性
·
为什么我喜欢富于表达性的编程语言
·
计算机专业的女生为什么要学编程
»
更多知识库文章...
China-pub 2011秋季教材巡展
China-Pub 计算机绝版图书按需印刷服务
<
2005年8月
>
日
一
二
三
四
五
六
31
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
1
2
3
4
5
6
7
8
9
10
公告
欢迎光临我的小站!!
昵称:
vagabond VS net
园龄:
6年6个月
粉丝:
0
关注:
0
搜索
常用链接
我的随笔
我的评论
我的参与
最新评论
我的标签
随笔分类
心情故事(2)
(rss)
随笔档案
2010年1月 (1)
2008年1月 (1)
2006年9月 (2)
2005年11月 (1)
2005年10月 (1)
2005年8月 (2)
2005年7月 (5)
文章分类
设计模式
(rss)
学习AJAX
(rss)
NET技术
最新评论
阅读排行榜
评论排行榜
推荐排行榜