该用户从未签到
|
登录协同工作平台安全解决方案
% f' M1 P- W9 d; v[摘要]公司领导说登录验证的安全性如何保证,建议采用UKEY验证类似网银解决,调用第三方YT公司产品。 解决方案:
; e) N5 Q2 Y4 H8 T9 @
前端页面: - <embed id="s_simnew61" type="application/npsyunew6-plugin" hidden="true"> </embed><!--创建firefox,chrome等插件-->
( }& ^) f8 {2 o6 _: v& d - <script type="text/javascript" language="javascript" >
9 |6 X* [! x, c5 \4 N - //加载皮肤
$ B5 [3 o4 _1 g' x3 x: Q3 G ?! H - var setTheme = function () {7 d; e) g2 y0 R+ L9 ]
- Ext.net.DirectMethods.GetThemeUrl(cbTheme.getValue(), {. W" S. z/ G3 t B! D5 t) M2 s7 v
- success: function (result) {
& q2 f7 l$ }! @8 @1 X# n - Ext.net.ResourceMgr.setTheme(result);
4 Y; m3 j4 n, H( U4 g7 o P - }
3 Q4 | y4 _6 Q4 s# V" u - });
, i5 R$ }* c0 ^+ W' Q5 Z: g - };
5 |5 |. n6 K% a5 T - //回车出发
9 F, C9 n1 z$ O - document.onkeydown = function (event) {- k8 A R5 R) k4 r* S2 S' t; C
- e = event ? event : (window.event ? window.event : null);
! b5 o. l" e. x. U) k6 T - if (e.keyCode == 13) {, ?2 Q& Z1 g ^# Y% r
- //执行的方法 / `- }$ D# F9 d$ d
- //alert('回车检测到了');# F2 h Q5 @1 _
- //Ext.net.DirectMethods.Login();- E# E k3 R. t a
- login();; X( V) l. {% ~7 Q7 m L; Y0 z
- }" ~* z: F! t8 ? C2 ]. x; Y
- }) M$ B8 E; p a! ?, j2 M( W8 }
1 Y# {4 V* |+ k" @- var digitArray = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'); a) A5 O2 I' y, i* p2 l
- function toHex(n) {7 W1 L6 S! Q: ?) o+ R+ O
- var result = ''
/ _, F9 ?% l( h* u& C* [5 X - var start = true;
/ z% x$ B- c. z9 n( C8 v8 ]: T: @# [ - for (var i = 32; i > 0; ) {6 q5 d; w+ W, ~7 a* w' w
- i -= 4;1 i/ h6 q/ X1 S' [5 B/ z0 [
- var digit = (n >> i) & 0xf;5 z$ V- a) i5 V" h, j% G
) K% l- U8 i$ t) r' i4 ^- if (!start || digit != 0) {$ l( }9 p$ J+ _. L- n% ^! F
- start = false;
( U, \# d# A9 q {, | - result += digitArray[digit];/ J. b3 \ l B0 r4 A
- }
0 l e3 D- h3 u% [- l) y5 a - }% [0 X1 H$ k* B" a9 k
- return (result == '' ? '0' : result);1 f0 o- q! `( {) m
- }' O: }, q L: |6 E0 y3 K
5 d- X+ D/ O+ T z6 `$ Z8 u- var login = function () {. Y/ P( J, l& z n
- var IsCheck = 'N';6 {5 @+ k3 E# e) q& M( v( |
- if (window.location.host == "localhost:23111") {) p$ _6 D# ?" P( C$ i: d1 w/ q. n
- var DevicePath, ret, n, mylen;
7 Z# p" J5 X: H - try {
; F7 q3 J& _- {+ x- d! A5 ^/ K5 ~; T* \ - //建立操作我们的锁的控件对象,用于操作我们的锁
' y. l* ~9 z% o7 e1 z - var s_simnew61;; p7 a# N5 n, }% M# F
, C5 D$ x) p4 \# l- //创建插件或控件2 `+ \6 M9 x0 l3 J& p, y; ~& {
- if (navigator.userAgent.indexOf("MSIE") > 0 && !navigator.userAgent.indexOf("opera") > -1) {
- r/ Z% Z2 w& e2 A - s_simnew61 = new ActiveXObject("Syunew6A.s_simnew6");
& c7 H, F1 H: y; C' d5 \ - }3 |& \5 v- }( R- U) _
- else {7 S# Z& |. V' d: R. {
- s_simnew61 = document.getElementById('s_simnew61');7 r3 F) ?* @& z2 s+ j
- }
3 L! G1 B5 } T' E
7 D I& {8 O+ [# W- ( f* y% c# Z: ]5 s% L
- //查找是否存在锁,这里使用了FindPort函数) r6 p. h( g1 w
- DevicePath = s_simnew61.FindPort(0);
$ k/ t- i# {+ c/ |# Q, V, K - if (s_simnew61.LastError != 0) {
7 E3 V8 w0 |, G - window.alert("没有找到Ukey ,请插入UKey");& A* `9 ?) F% p8 B, f
- //window.location.href = "err.html";
* h. A o3 V! H! e" c a - return;
0 H# q4 r+ u' ~( C7 H- L5 G - }; j5 U& c& A" `; C* h( t
- " O8 ]3 ?- B4 g
- //这里返回对随机数的HASH结果
! e& s8 P/ w1 b - frmlogin.return_EncData.value = s_simnew61.EncString(frmlogin.rnd.value, DevicePath);+ u1 w( p' B1 m4 i
- if (s_simnew61.LastError != 0) {
8 ^5 X! b! u: |; p/ r# y" ~ - window.alert("Err to StrEnc,ErrCode is:" + s_simnew61.LastError.toString());4 U) m' O! S( k4 ?! h4 D. P
- return;1 C5 p' N" |8 Y1 a
- }
* O" b) x9 x& s& |: x, @ - IsCheck = 'Y';
o) E* H& W$ S- _% x - 0 {$ |$ l/ v+ r9 t" {& ^3 M1 G9 ^
- Ext.net.DirectMethods.Login(IsCheck);" O8 Z% Q9 e4 y& z- o& H
7 g- h/ d" Y4 B* X. p+ {- } catch (e) {+ k9 {* {: [7 \' e0 {
- alert("您在使用外网访问:" + e.name + ": " + e.message + "。可能是没有安装相应的控件或插件");
# \6 i+ h& J; C& M' E$ g - }' B2 _5 z# a2 Z4 @: X( d" F
- } else {
0 a+ v4 Y: x2 b) [2 W6 V) K - Ext.net.DirectMethods.Login(IsCheck);
+ A0 ~ g; }( W6 E0 ? - }" \0 Z3 p# G: e
! }& t1 D5 u# v0 S& I; ?: C- };
0 l+ f$ {* F! z4 |6 a- E4 V+ { - </script>
) S" |3 g- O7 k& K. J) ] - <script type="text/javascript" language="javascript">* z- D- n$ D; {8 e, q3 c# x
- function reloadCode() {, F/ U/ ~( ^ u9 V% |2 n1 [! |$ b
- var obj = document.getElementById('imgCode');
9 [% P8 Q3 ?7 ~! J" W4 F9 j9 o9 P - obj.src = "VerifyCode.aspx?";
" u# s h7 W$ A4 n/ Z - }& O3 X4 B. M9 k6 p; a& j
- ! ^$ w) H, I" }9 T, `2 L d* e: I
- </script>; D. |: I' Y$ o' l
- CS代码:5 Y! W& p5 P" V) y$ @
- SoftKey2K ytsoftkey;
0 e: d& X4 z- `3 l7 C; W# [: T' l. S, K - String KeyPath;
1 Q- Y9 c) E* T0 _3 S8 B - private string _randomcode;
, z% g9 E$ [8 u' X - /// <summary>
1 A% `! x/ |, R3 b ~' R6 q. c+ C/ J - /// 随机数
8 h' [( X; u, t% E* H- ^6 d - /// </summary>
$ l3 c1 A' O4 v/ o! I0 S# Y, h, o - public string Randomcode) G1 J& B6 w2 o. A- s
- {9 i0 y) B- C- I l" g. ^) C
- get { return _randomcode; }
/ ^9 X: R$ A# W+ _; t) |- B2 t, E - set { _randomcode = value; }7 ~7 H! a, m b1 l6 [2 {7 M, K
- }
1 j9 C/ E A4 p8 F5 J7 X* `, p" h8 m' k - protected void Page_Load(object sender, EventArgs e)* w' ? P+ `8 d# X
- {
+ E9 v6 o; y; O4 B' T& V - if (!IsPostBack) J6 n; g0 l' U6 T( P
- {7 p6 H1 O$ x+ [8 }4 r1 C
- System.Random random = new System.Random();. `' \; N: J0 L- D- C" S* n
- Session["rnd"] = rnd.Value = random.Next(0, 2147483646).ToString();2 F) V- \9 L$ N- v$ u1 D' K
- Response.Cookies.Add(new HttpCookie("CheckCode", ""));( I. L) A( t9 Z& t
- }2 R* {' k8 M" t# C2 \
- }; E: V$ i# O, r" m& m
e5 z% s! j. R" Y/ C" d$ F+ G! F-
! h6 M: R [' d. X! a) V3 G9 s - [DirectMethod]* V8 O! I; M5 W- t6 L$ R% K/ B/ Q
- public void Login(string IsCheck)
1 a' b1 E* s1 V5 L+ m0 Q% ^3 H" u - {
% b, C6 R& \* d+ f, \' u# ]9 v( \- D - Check(IsCheck) ;
: H+ ~0 I+ V V% l! f/ z' D -
" \! h0 d6 S' ?1 F, J9 t! a; x0 O3 Y - }7 m b* [2 a4 A. x
- /// <summary>
: ^1 ^" I: s/ {' ^- D* q+ l4 a - /// 登录验证8 q7 T1 v% f ?6 t$ E
- /// </summary>5 N( s% \; I4 G: x) Z$ _
- /// <param name="IsCheck"></param>) N4 ?6 s. J2 s0 W/ w
- private void Check(string IsCheck) + k& I* {" {" W5 l$ {, |
- {
# Z( s5 E: @0 K4 s. A, o8 `6 @ - if (Request.Cookies["CheckCode"] == null)# e5 y! w \, v3 n. q' W1 P: H3 m' t
- {6 v& V1 Q: q- d# {, I/ ~
% g. ?1 p' @( K- Notification.Show(new NotificationConfig8 |( w. _' m8 z: R+ {: n
- {
: O2 |" D% P! s - Title = "提醒",, q" `# z! Q9 G5 e) u6 t4 f/ Q
- Icon = Icon.Information,
" j9 ?3 n# F/ p6 s* S X5 J7 J( w - Html = "<font style='color:red;'>您的浏览器设置已被禁用 Cookies,您必须设置浏览器允许使用 Cookies 选项后才能使用本系统。</font>"
/ E* m- Y: d8 B( Q; b! l2 u( s - });: z# ~3 v! i/ n; m5 N
- return;
@) ]( A% f! H, [6 { - }& Q! T# X- ^$ E* r- C/ ~
- //验证码比较7 N' `4 @% |9 v; ]
- if (String.Compare(Request.Cookies["CheckCode"].Value.ToUpper(), this.txtVerifyCode.Text.ToString().Trim().ToUpper(), true) != 0)
Y7 Q/ d1 P+ R- j) z: ` - {
1 y& U) D. B- p3 f - this.txtVerifyCode.SetValue("");
. K& M; ^( W4 M, G - Notification.Show(new NotificationConfig
" f" ^% F1 y: ~- l3 Q - {+ q9 O1 C) `/ Z" i
- Title = "提醒",
0 U( `+ v& h" D0 M2 Q c - Icon = Icon.Information,0 F' @" x0 @2 k3 t
- Html = "<font style='color:red;'>验证码错误,请重新输入</font>" w7 O$ n& Q. |% [+ k u
- });
' _: } C7 E; {+ t6 L& ]4 T - X.AddScript("document.getElementById('imgCode').src='VerifyCode.aspx?';");' z0 c& \) M- r0 A4 S4 R
- return;6 C3 m, e. [! f) z" \
- * h5 _; A6 q9 N: E9 b' p
4 r3 ?$ ]( ?1 V! I0 v8 N P- }' o5 c% @5 v8 _2 \; H/ F
- else
; @$ M3 P* G# ~) a* ^# M8 { - {9 @1 |( X' Y: l4 V2 L8 ?
- Utility.MD5 md5 = new Utility.MD5();
/ H$ H; d/ l7 j9 F$ k - DzPlatForm.Model.Users user = new Model.Users();2 \" W6 e& Q) ^1 t9 I7 Q
- user.USERNAME = Utility.Baseclass.SqlFilter(txtUserName.Text.Trim());//过滤危险字符
3 o x: w3 A1 Y' q/ a - user.PASSWORD = md5.MD5Encrypt(txtPassWord.Text.Trim());// md5.MD5Encrypt(Utility.Baseclass.SqlFilter(txtPassWord.Text.Trim()));//密码进行加密 s s( C- A! [# L# _& p/ @$ }
- ! x% p$ @, v4 \$ _
- string sql = "select * from [users] where id=1";9 ]8 |4 N: E. ^% M) b& [
- DataTable dt = DbHelperSQL.Query(sql, null).Tables[0];
7 M/ f' Q6 o, ^ s - ( l7 E1 h% `; c/ G/ J* {
- DzPlatForm.BLL.UserBLL usermgr = new DzPlatForm.BLL.UserBLL();3 c7 C* v1 Y4 A. D+ H. `) K
- string UserId = usermgr.LoginCheck(user);/ J% x3 v# Q! C, V/ c9 B
- * n6 G) ?9 C* r" l' B
- if (UserId != "")
5 t/ r: |6 X: R. l% q3 D# ?# i. M - {6 F% v/ q& R, ^" n6 B" o
9 {3 V! @+ W+ ?8 c2 B/ z- Model.LoginLog lg = new Model.LoginLog();
1 K0 I/ i7 X$ ]7 t# o - lg.Name = txtUserName.Text.Trim();! `3 C, P# j% K( `3 H
- lg.Browser = Utility.IpBrowserHelper.getBrowser();3 } u+ Q+ i3 L; i$ F7 |7 N1 U
- lg.Ip = Utility.IpBrowserHelper.getIP();0 K1 Z; H/ n3 b5 f# p* T
- lg.System = Utility.IpBrowserHelper.SystemCheck();) }0 ^3 f! V, w! G% K. q5 g. S
- BLL.LoginBLL logmgr = new BLL.LoginBLL();
1 \5 P9 N% ` ~ - logmgr.LoginInfor(lg);
* X% u4 \$ {+ w7 @& y' G6 x - usermgr.Record(); d* X3 @( b- @- f1 v, Z
0 Z) Y8 V% e0 f2 R6 m- Model.Indentify idf = new Model.Indentify();
( j0 Y9 W& P% P' M! b$ N - idf.Userid = int.Parse(UserId);
% Z2 R, c- @% W! }* U - BLL.IndentifyBLL idmgr = new BLL.IndentifyBLL();
+ {9 u; ? c- @- P - idmgr.GetIndentify(idf);: z" C- W( y9 r
- Session["userid"] = UserId;
4 z, ^/ ~' E2 \# L5 q/ d - Session["UserCode"] = txtUserName.Text.Trim();
) I9 g" K5 W r: v - Session["UserName"] = idf.Name;2 @0 ?7 P* P. B- _7 V2 U! w
- Session["utype"] = idf.IsSystem;, @: f7 n1 O- L
- Session["uip"] = lg.Ip;2 k4 g. f/ R' E$ P5 ~' \) p$ ]6 D3 P
- 1 ~$ b, i F* L
5 r: A* O* u5 D9 {2 d" O( _- //X.Msg.Show(new MessageBoxConfig; i$ C# v+ E, s: }; g6 p! o
- //{
* M. W( @+ t% Z5 d - // Title = "请等待",
% a/ J* |& S8 E& _/ `8 G - // Message = "正在加载项",7 g& b3 O+ Z% j/ _# U
- // ProgressText = "初始化中...",
! c: ?0 K% h n" @4 ^/ e- E - // Width = 300,# {' F% M# j: Z
- // Progress = true,) I/ P& ^( @) |) ^; [8 Q2 ^5 k) U
- // Closable = false,9 V/ k' G3 ?# x
- // AnimEl = this.btnlogin.ClientID
; w( W% Y! P6 v o - //});
' Q. ~; c. L0 Q - ) l: c8 o w! ?- Y; n: k" V
- //this.StartLongAction();
6 p5 c0 i2 z6 A3 y - String strData, m_StrEnc, Key, Flag; p/ O$ E) P( K
5 K! R/ ~5 G) s/ X. ? M- Flag = IsCheck; ^6 X$ H7 z% x. {6 r
- //Key:即增强算法密钥,这个要与设置在加密锁中的密钥一致
" @* F+ z/ J4 c# D# b% e - //增强算法密钥可以是每一把都不相同,也可以是都相同,如果是不相同的可以根据用户名在从数据库中获取对应的增强算法密钥,可以根据安全性及自身具体情况而定,这里使用了一个固定的值1 `3 {: b: D$ x) o
- // Key = "1234567890ABCDEF1234567890ABCDEF";
1 j+ V( [; n: D3 J - Key = idf.UkeyCode;+ t/ T }8 L0 w! j
- //strData:要进行加密的数据
% u" f3 o* @6 A" Z$ M - strData = rnd.Value.Trim();//Session["rnd"].ToString();
# M0 F) ~- o5 L/ `5 g* j- d7 V( I - //'在服务器端对数据进行加密运算
1 X: Q: z* Q; X8 N. t2 t - m_StrEnc = Global.m_softkey.StrEnc(strData, Key);
. U+ P7 F+ l5 ^* Z - //比较客户端加密锁返回的加密结果与服务端的加密结果是否相符,如果相符就认为是合法用户,由于使用了随机数,从而实现了一次一密的高安全性,可以用于高安全性的身份验证
2 v/ J! }- c* X# |% x! R' H - if (Flag == "N")//内网不需要比对- k; {6 V8 N U) ]; s5 m9 A
- {2 u4 K+ r u1 i2 P! L! u
- Response.Redirect("Index.aspx");* g, F0 D; Y. J% Y' [
- }
8 x: [$ }* [ F t. a) ? - else0 a9 a0 K% A# ^; \$ R
- {
. n) D) { ^5 ? - if (m_StrEnc == return_EncData.Value)
8 }& e& W' S4 E" ]9 C) e - {
: Y5 y/ G6 M+ B - . X* O' f7 v& x/ o A
- Response.Redirect("Index.aspx");' ?1 q0 e- g* s: e
- }; @4 O# k. \4 I0 r X: p
- else3 e" i* s5 `/ `. Y2 N
- {% Z2 Q; U" Y/ |3 s- ^" ^" k
- Notification.Show(new NotificationConfig1 ^ z" ]+ i" p7 O4 M" S
- {3 [: v) e# X1 b8 q
- Title = "提醒",
5 b$ k/ p4 R" n' ~% v& T- A& r! p) } - Icon = Icon.Information,
& K4 v! `4 q: z1 Q9 u( N- ^ - Html = "<font style='color:red;'>该用户不是合法用户!</font>"
% n+ D# D" b. J: l n - });
9 w, B! E7 e$ E2 Y" ? - }
& [ e B2 ^; t* L0 I, H* M - 7 b! x8 {1 W4 f2 w9 k
- }) R; r$ b) P! a
2 p- H8 E' p& g' W N- }
& i1 x% o2 o: T+ \. Y, I% ? - else( S- K0 t' W% O+ B- ], v
- {$ Z4 z \; W( u" D$ O- K
# z% }: [" c9 ^( H% f* V/ y- Notification.Show(new NotificationConfig! N4 H2 g0 Q# Z, j! k
- {
& H% G/ J( W/ ~ - Title = "提醒",0 F( U& Y; L! Y, b, T( g
- Icon = Icon.Information,
8 c& e* I- y( M& S - Html = "<font style='color:red;'>帐号或者密码有误,请重新输入!</font>"
W2 `' v/ m5 v* Q - ! b }' I( B. d/ F/ v7 p3 l* B3 f2 X! H
- });5 t* x0 o; R4 T6 Y) c
- X.AddScript("document.getElementById('imgCode').src='VerifyCode.aspx?';");) N( Z0 n" f/ F; L* j" p
- }
( m: w% q5 t! A - $ }7 N9 S6 K, F" i- |0 F6 G
- }
6 N- J4 w4 f2 b. M# |# y - }
- E6 N- U* D% t: y5 c" X - /// <summary>
3 M4 W3 ~) e8 h - /// 开始计算任务
/ w. t! m% p1 F- r; H. H; f - /// </summary>
. c; X1 C2 h' n+ N7 ^; g! [' u - private void StartLongAction()4 h5 D# k2 c, c- N8 s
- {
5 b3 N9 q- u; R7 q - this.Session["Task1"] = 0;
- r. K/ ?/ S. I$ n" p) ` - ThreadPool.QueueUserWorkItem(LongAction);
3 q2 J3 @) V( V/ J6 `8 |% n, i
- q: k4 M. \% A- this.TaskManager1.StartTask("Task1");' g7 ~1 P+ [4 C& \( w3 I* n
- }4 U7 W- x0 w/ X* v
- /// <summary>9 {( B& A+ |: s* v4 ]' v% q2 D; h3 k6 N
- /// 计时器. D7 }0 x. H5 g4 T0 g
- /// </summary>
/ Z# E2 k$ `, l. P+ V - /// <param name="state"></param>
' H+ Y/ c! e4 `! ]) s( r - private void LongAction(object state)
0 M* [- e; N1 r# e4 S, t - {
0 z# M- ^2 Y# ?8 M+ f/ a - for (int i = 0; i < 100; i++)6 b) h( w1 q" l. P" L/ `! z( D
- {
5 O% N; g8 G j+ T" q" ~: R, R - Thread.Sleep(10);9 o+ V! C& b/ p
- this.Session["Task1"] = i + 1;
. L9 x; K' @: _0 e; K - }( L6 Y4 q3 O/ g' `# ^
- this.Session.Remove("Task1");
6 \7 s: z9 N8 B) K7 R- A8 n - }! x/ {2 g0 c/ J+ ~7 [ E, l
- /// <summary>- y7 k3 e5 `! ]9 w1 f
- /// 刷新进度条5 O" D8 E9 |/ S
- /// </summary>; e* h" G+ e$ b+ R, B0 m
- /// <param name="sender"></param># g* s7 ^5 o9 m7 W( m; A
- /// <param name="e"></param>
" K D/ ~2 P7 Q$ T# o% _( g - protected void RefreshProgress(object sender, DirectEventArgs e)+ x( |% B) [4 m. h, `( g
- {
, X; l$ p7 x8 c& a+ X3 l2 w1 Q/ k - object progress = this.Session["Task1"];
# i7 S( V; S ~9 p# d Y& D - if (progress != null)7 @) e: P2 t' l/ ]; {
- {( J+ c4 `- C# h7 z q
- X.Msg.UpdateProgress(((int)progress) / 100f, string.Format(" {0} % {1}", progress.ToString(), 100));
/ g. B3 R' f' ], N: H1 [9 z- \ - }$ \. M B8 ^& v2 C o" g1 c
- else5 H- P; C+ n1 i9 H/ O
- {+ W6 G( a! F6 ^' T3 g! @( i0 q
- this.TaskManager1.StopTask("Task1");
5 Y; q# z5 K+ R1 ? - X.MessageBox.Hide();
& }- V2 m# W6 q) H( m$ i - Response.Redirect("Index.aspx");
: R! J- a# {0 s& |& D - }
; n6 g: G& b6 @4 g# A4 ? - }. z, H+ V2 a8 M9 C3 M f
- /// <summary>7 U, M6 X6 h- J4 V
- /// 更换皮肤
5 N7 }( L5 E2 }% `+ u - /// </summary>
W% a" `& u3 N - /// <param name="theme"></param>2 n6 j/ Q- p5 L& I1 T6 ~ ?! c
- /// <returns></returns>
; b, M: M7 B0 @& j, A) A: t - public string GetThemeUrl(string theme)
9 M$ G: J* T; @0 p2 H* a; s - {
) K2 `- u9 f9 C: [8 b - Theme temp = (Theme)Enum.Parse(typeof(Theme), theme);# G2 R3 d( p" g! a/ b: T! r
- this.Session["Ext.Net.Theme"] = temp;4 C* ?3 {2 x- ?1 D% f
- return (temp == Ext.Net.Theme.Default) ? "Default" : X.ResourceManager.GetThemeUrl(temp);" \6 n3 z1 ]5 f8 G% Z: J
- }
- }- c: s9 r) r8 |. B - * h6 P, Q* @) Y) j+ G
- }
: e+ ~% b2 a$ F/ B
' _8 D+ U7 {/ R7 |# Z1 R- 服务端代码:Global.asax" r& ]2 \& F" P) P- Z
- public class SoftKey
3 V7 s3 }# s! C3 E - {0 }+ [. H c. H' {$ X/ d& z
- [DllImport("kernel32.dll")]
% g/ O) i" u) D - public static extern int lstrlenA(string InString);* a" l5 |- C& Y! t$ e4 |9 i
- [DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]+ |8 i; T1 S% j- S3 z
- public static extern void CopyStringToByte(byte[] pDest, string pSourceg, int ByteLenr);
9 s" I0 J: h/ } - [DllImport("kernel32.dll", EntryPoint = "RtlMoveMemory")]
8 M) a5 P, K$ k( U. n2 u - public static extern void CopyByteToString(StringBuilder pDest, byte[] pSource, int ByteLenr);8 T9 E: H4 i* u
- & x( o* n9 u& u4 l7 ]7 Z
- //以下用于将16进制字符串转化为无符号长整型' {4 M _6 S, ]5 ]
- private uint HexToInt(string s)
! \3 {$ s( n, e: B5 i - {, i! g* f4 L. [
- string[] hexch = { "0", "1", "2", "3", "4", "5", "6", "7",8 @. x5 F' |6 I* p
- "8", "9", "A", "B", "C", "D", "E", "F"};% ^, G- u' W! Y# q2 |8 ~+ ?! l
- s = s.ToUpper();
3 `8 t/ R& m* R- U - int i, j;! d9 |5 ^; f; u; G7 \0 q
- int r, n, k;1 b9 ]/ V% B. p8 r% }
- string ch;
! L: c P) [: G
) w# u$ n) n+ T% H0 q3 T1 s- k = 1; r = 0;" D& P, r% R* _) b1 A3 @0 I4 n/ z
- for (i = s.Length; i > 0; i--)
2 W8 _, j9 |) q+ _- [ - {
8 I% L2 ^" |3 P - ch = s.Substring(i - 1, 1);4 ?& y, Q2 Z8 I
- n = 0;
3 x7 Y4 _; c( P/ q+ V. j - for (j = 0; j < 16; j++)
) _9 t, h* T ~6 U" `( y/ Z: M2 A" U - if (ch == hexch[j])2 a- W" | X5 G/ Q9 O/ R: \- i' |( n
- n = j;
+ T! g, S: _) ]# L% y5 S" [4 B9 X: F - r += (n * k);
9 z$ w, m- j) o% P0 Q - k *= 16;% T6 ~# a3 m9 t* t: k, d
- }4 V2 T, t( M5 _3 ]% O, [) d. E( |
- return unchecked((uint)r);4 g4 z8 D% G3 m' V
- }+ L2 J r2 _& X+ [7 q* [' g8 I3 [
- & E- i& g% v* e7 X2 M3 X2 |9 g
- ) u _) [3 Z* v
- public void EnCode(byte[] inb, byte[] outb, string Key)
\. Q% B8 E- l! I6 m: d2 Z - {
8 A% q5 ?1 v6 t7 b6 F6 I( x6 r9 j - , }2 z* t3 @6 N& H
- UInt32 cnDelta, y, z, a, b, c, d, temp_2;
8 S i, I7 J) h$ d! @0 `4 C, t; o! e - UInt32[] buf = new UInt32[16];
& p% ?% s- ~5 E( @8 Q - int n, i, nlen;
* Q% \& ^6 r' T4 P - UInt32 sum;, h9 ^! w5 X g+ e, F: c
- //UInt32 temp, temp_1;8 O" p1 L0 e2 L; p
- string temp_string;, q2 l4 @8 z* T5 N
; ?* i! J* W* [3 p3 D& x
' |! a* @: D+ N- D- cnDelta = 2654435769;
* Z5 j8 A/ c; i( p4 o ^ - sum = 0;
" O+ T+ A6 O. U0 X
, z1 C1 e+ U# v* R& T& h+ a9 @' j$ ^- nlen = Key.Length;$ g7 C0 I; y* b( u9 [3 n9 u
- i = 0;
* i: v, O- z' @1 D! n# `% V - for (n = 1; n <= nlen; n = n + 2)1 p" J* W1 }3 h/ s
- {% K$ v0 D5 L; M _; Y& H9 i
- temp_string = Key.Substring(n - 1, 2);) z8 }0 p( h+ j4 I5 B k) ~ q
- buf[i] = HexToInt(temp_string);
; P/ L0 W% ^# j# Z, M/ w) O - i = i + 1;
n( C5 o( |3 U( R! T7 [3 I - }2 H3 R( Z, S' \7 K7 R7 |
- a = 0; b = 0; c = 0; d = 0; c6 w N* R* T# q
- for (n = 0; n <= 3; n++)
; ~7 ^; V: F; |* R8 S% J - {2 l9 q% t4 D; {$ Y8 o/ v- s) V8 V
- a = (buf[n] << (n * 8)) | a;) n/ C" W( P1 L
- b = (buf[n + 4] << (n * 8)) | b;
" H# r/ e( ^& j0 U1 h% i4 \& X0 w7 _, a - c = (buf[n + 4 + 4] << (n * 8)) | c;
, W' n" g1 `1 e5 q - d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;
# r' { g, ~1 n) @& q9 h+ S I$ W - }
/ h8 S- Q. T, h. }1 I/ W - ) i2 X. k$ [6 y! k* d: Y
- ; t: @& ?' q. J; [* v) z
, J# F0 k( X( k# z) f; ]3 r- y = 0;
! m" |5 j( J0 r' m$ e' d7 n* u - z = 0;3 J. Z- y. L) `' ?" y
- for (n = 0; n <= 3; n++)0 M# x6 ~1 Y/ S
- {
( Q6 Z' M( S1 |$ W/ [ - temp_2 = inb[n];
5 u4 l" X: o" B - y = (temp_2 << (n * 8)) | y;
, O0 R5 Q& ?2 T7 c/ n0 ?% z - temp_2 = inb[n + 4];/ o% z$ L9 o8 G/ F, c0 _- |) |2 w' ]
- z = (temp_2 << (n * 8)) | z;
7 r1 x; F( g' ~8 ~0 K9 x7 m, i - }
$ g3 D/ d: Q5 j/ ?- p4 Q5 `
5 _. ~8 Y. E9 A4 [" n4 R: W- : B$ j7 u3 q1 [# F* F" u
- n = 32;- ]2 G5 B& a7 ~1 v* C, i7 V
7 `- [) f2 E% P4 G/ n- while (n > 0)
$ t, T; Y' k2 x2 @) ] - {
8 p0 S: A: Y' j" A2 W0 O2 u+ U - sum = cnDelta + sum;& S5 r( i, J9 d) y; m5 J) p
- / K! E1 [/ O1 _
- /*temp = (z << 4) & 0xFFFFFFFF;
; N/ z, B% [7 T1 k0 \ - temp = (temp + a) & 0xFFFFFFFF;
+ B+ {9 I" t/ u# E, ^# q" b+ R - temp_1 = (z + sum) & 0xFFFFFFFF;
5 u8 B6 H0 \8 g& y - temp = (temp ^ temp_1) & 0xFFFFFFFF;
; J5 E# Y3 X9 g% p - temp_1 = (z >> 5) & 0xFFFFFFFF;
+ p# v% a6 p# y1 E - temp_1 = (temp_1 + b) & 0xFFFFFFFF;
$ T% W& a/ [6 V1 v9 ^( ~ - temp = (temp ^ temp_1) & 0xFFFFFFFF;$ D! t( E& U4 S% [) Q/ T" j8 L0 W
- temp = (temp + y) & 0xFFFFFFFF;
2 v; S$ j$ ?/ o$ g- _/ ~, A - y = temp & 0xFFFFFFFF;*/! r; R( f7 h( J6 l. x. r3 M
- y += ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b);/ z$ h, y3 ?5 w5 X
# p3 B) G i5 b- /*temp = (y << 4) & 0xFFFFFFFF;
4 F& S7 x3 v. x! X _$ J5 e# Z - temp = (temp + c) & 0xFFFFFFFF;
4 u$ D4 w7 l5 p, h- I - temp_1 = (y + sum) & 0xFFFFFFFF;, j$ G3 e9 y2 `* C1 ^
- temp = (temp ^ temp_1) & 0xFFFFFFFF;% P2 B, i! T; D$ O* j
- temp_1 = (y >> 5) & 0xFFFFFFFF;- ^- b3 k+ Y- z. P( w
- temp_1 = (temp_1 + d) & 0xFFFFFFFF;
9 ~' x/ [) @+ B; v$ B - temp = (temp ^ temp_1) & 0xFFFFFFFF;
% }8 ^3 g% o* V6 t$ O - temp = (z + temp) & 0xFFFFFFFF;( W9 |$ t& |- Y/ g$ C9 W
- z = temp & 0xFFFFFFFF;*/9 ^* N5 x" T- ?, J4 M( ]* _' L
- z += ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
! c* `5 q2 U6 J- B - n = n - 1;- |5 V( `: [9 ]8 ^
3 e& @% a& K8 S( k5 L7 G- }
: K9 W! m6 m# R8 l! @ - 6 z/ i- [. M. v! h' y' R" u
- for (n = 0; n <= 3; n++)
! b4 a1 E: R1 i) g- F - {# Q& @- T1 J# Y: V" E0 g
- outb[n] = System.Convert.ToByte((y >> (n * 8)) & 255);
5 w" d% K- D6 b+ S8 q) q - outb[n + 4] = System.Convert.ToByte((z >> (n * 8)) & 255);
8 N! R( j+ ~ u - }9 z5 z4 Y; g: Q0 z- l* R
' x/ ]9 _+ D9 Z9 m- }
2 s! \( b- K# J+ [ - " ]7 Q8 c7 K {9 q
- public void DeCode(byte[] inb, byte[] outb, string Key), ?+ C" o' O3 M8 c
- {
, ]/ k4 F/ v) ]. i. j - 7 s8 N. k* U+ q) D" L
- UInt32 cnDelta, y, z, a, b, c, d, temp_2;
0 ^% n6 Q$ J+ G6 w) I+ H - UInt32[] buf = new UInt32[16];9 C# n, }: a$ p7 S Z+ A- v W
- int n, i, nlen;
6 N a& D8 r* U' v8 _ - UInt32 sum;
* E4 N% K3 r' ]1 S% o - //UInt32 temp, temp_1;9 ~+ V' I' E, l& M+ t
- string temp_string;% n3 ^; u0 ~4 u
- % v3 {( m! P' O
- # s5 V: U) v' D) i4 j/ j( q
- cnDelta = 2654435769;- Q% [/ l/ r# c$ Z9 i: A0 U
- sum = 0xC6EF3720;# g$ W8 e' H0 G# b$ G2 u0 U h
- + i3 A, V: s5 u/ O: i) b2 D
- nlen = Key.Length;
( D- p0 ]3 Y! t" ? - i = 0;9 Z3 ^4 d* H% C) ?. W1 v
- for (n = 1; n <= nlen; n = n + 2)! v, }# A5 T9 M
- {/ C$ f4 s/ p9 _' y+ y
- temp_string = Key.Substring(n - 1, 2);: J7 J3 j, b+ y: ~0 e9 d$ ~6 s. F, g
- buf[i] = HexToInt(temp_string);
1 O3 }+ S0 k! x* i6 v. K - i = i + 1;
; J. ?' i) B: w1 B( K - }* x- X, @) c# `
- a = 0; b = 0; c = 0; d = 0;
7 {% D) \: g* C+ m# z - for (n = 0; n <= 3; n++)3 O* F& @( n/ b9 A
- {8 ^$ V% S$ T' c" l; w
- a = (buf[n] << (n * 8)) | a;
5 U/ g# N+ {/ c0 @8 F Q - b = (buf[n + 4] << (n * 8)) | b;3 ~( @; H0 [- C
- c = (buf[n + 4 + 4] << (n * 8)) | c;) P1 [) Z/ v7 e
- d = (buf[n + 4 + 4 + 4] << (n * 8)) | d;8 S! B7 E( K6 d# X
- }6 f! P1 j# g7 N: ~' B4 i! m& L
- / H* \5 l* h4 B# t" O
9 ]1 v7 c$ P6 `# C- ( u* u/ j! d0 S: X3 a
- y = 0;+ v* {% E1 D/ N1 l( m3 i. j
- z = 0;! ?( n, G$ {. V+ V. w: m9 d
- for (n = 0; n <= 3; n++)
& Q7 Q% g: c( }. W' L0 j9 G+ g - {4 M7 L. q7 D2 Q- C. x
- temp_2 = inb[n];- x3 V- @# O7 b/ K9 i
- y = (temp_2 << (n * 8)) | y;
+ v* @/ K' `% X4 [ - temp_2 = inb[n + 4];: b0 v' ~" \& v. H' F K
- z = (temp_2 << (n * 8)) | z;
$ _/ L* f+ y! S! l - }
: ~. X! v$ p0 {( a - 6 h0 d( K9 O# Z1 C
- / B& P# s/ {9 \" W
- n = 32;
# z- [/ o+ u0 B6 r$ J; g# L) P
0 o1 G* T) \: j# U- while (n-- > 0), d) X( L5 n( U7 `9 i- g+ {: g
- {2 T" S2 |; W/ M; _1 Y
- z -= ((y << 4) + c) ^ (y + sum) ^ ((y >> 5) + d);
! w) C z" Q8 X* H1 s4 o - y -= ((z << 4) + a) ^ (z + sum) ^ ((z >> 5) + b); |1 a4 `* o% J
- sum -= cnDelta;
' B8 A' j* R0 j) C3 g: A3 ~% u - 8 u& P' o# u7 }: @
- }! I; h) i0 m' L& E
- # \3 u \" c( \3 n( Z O5 K
- for (n = 0; n <= 3; n++)
5 t2 h7 C# ^+ s# F; s+ g - {7 [8 C6 P6 U6 r
- outb[n] = System.Convert.ToByte((y >> (n * 8)) & 255);
0 v. u5 T. L- C5 ` - outb[n + 4] = System.Convert.ToByte((z >> (n * 8)) & 255);7 J$ W* l6 ]+ K) t
- }- I, f7 q/ C3 }6 R1 `8 s
- 0 r' |. v! D4 R" G8 h; ^! y
- }5 M6 l% b; H8 Q- |, ?
- 5 {; c/ g \8 t8 O! |
K7 Y, {6 s# C1 I% J2 Y$ {- public string StrEnc(string InString, string Key)//使用增强算法,加密字符串
. r* V& r; Y6 O5 r5 L. ?; a - {! \0 S. I5 ]: M5 }$ | _ y
7 \4 d7 O/ y. _- byte[] b, outb;1 z. [0 ?+ @5 N/ P, v
- byte[] temp = new byte[8], outtemp = new byte[8];
; ]8 o8 f8 }3 A& t3 k - int n, i, nlen, outlen;# B0 c; S* p: ?& h& ^9 F
- string outstring;
3 T. ~3 u% N- a - 1 y4 d& q: x2 Q" X
' |5 g2 g5 s) W; y* O- nlen = lstrlenA(InString) + 1;
2 k+ Z z7 ]" t - if (nlen < 8)7 j0 B j1 a8 a3 @# C
- outlen = 8;; h. N3 Z& \( k( D8 G. m2 @
- else
o3 d! l( G+ i% D# I$ q/ y9 q: r - outlen = nlen;
8 ^. l0 G h! R& \) e8 w D- I" ? - b = new byte[outlen];
9 h; i+ ]6 m# x- J - outb = new byte[outlen];; m8 p9 C8 h/ ~! i) G2 ?
- $ m) R- i6 r8 q9 x" k" v9 [
- CopyStringToByte(b, InString, nlen);3 A$ S7 _7 I9 c& x9 v- L
- 3 v' t6 a' m' f4 `
- b.CopyTo(outb, 0);
/ B6 {9 q1 q* A! T9 W. \ - * ?+ c: b; l4 C) ] J& y
- for (n = 0; n <= outlen - 8; n = n + 8)' M# [' \1 f, U8 i6 W* e/ X
- {# n. O+ g. I% ^: B9 N
- for (i = 0; i < 8; i++) temp[i] = b[i + n];/ C7 Z$ c+ q4 E7 J
- EnCode(temp, outtemp, Key);$ V0 j: ^ l: X1 w2 [2 f# `$ C. t
- for (i = 0; i < 8; i++) outb[i] = outtemp[i];: I) s0 B' L! o% }; {% w; ]
- }
4 c1 a0 a/ p* U* J; N- c - 6 B4 c% O" n% `0 A3 l
- outstring = "";
- g2 ? o& W( O, e - for (n = 0; n <= outlen - 1; n++)/ j \" n9 E' x! l n- {- u
- {0 U a% v' `% T ]' P
- outstring = outstring + outb[n].ToString("X2");
, N4 u% V% k7 Z: w - }2 s6 j8 ?3 W0 r$ S0 I# t
- return outstring;$ L4 J: L: k! C, Y
- }
& n$ M, @5 G, I/ ~# v4 S - public string StrDec(string InString, string Key) //使用增强算法,加密字符串
" t3 l6 \% X& K- p, S2 W* G* w - {7 E- C: Z9 x) t# o# V" b
- byte[] b, outb;8 \- E$ E! Q0 [8 o7 O
- byte[] temp = new byte[8], outtemp = new byte[8];) b" u2 f6 n/ x/ x% l/ c( X
- int n, i, nlen, outlen;2 H$ L- `6 ?* [$ _8 v$ G5 }
- string temp_string;) U! t/ g3 h- L# E) u! v- O$ A7 `
- StringBuilder c_str;
1 i2 L# W3 h8 j+ p+ j- B - 7 ?, h9 J& y) x6 m& F0 [
- 2 [0 B: `% @0 @1 C( k$ n
- nlen = InString.Length;, @" ~- d1 [' I; W0 A2 b
- if (nlen < 16) outlen = 16;5 A9 d6 Y: ^7 M+ X" t9 H/ S
- outlen = nlen / 2;; U. q; A' Z2 u3 r# Z
- b = new byte[outlen];1 @& a, p H. w1 U3 f
- outb = new byte[outlen];
k; `6 _1 j/ A2 g J3 t8 ^ - ; r1 h& f+ d6 ~4 p2 l
- i = 0;1 K8 F* t, J4 A- k) E9 }$ X
- for (n = 1; n <= nlen; n = n + 2)( T$ E( _' @, X) c" _3 r
- {
. o9 Q O0 f- o - temp_string = InString.Substring(n - 1, 2);
2 ~1 ?+ q# x% w# u; f0 V - b[i] = System.Convert.ToByte(HexToInt(temp_string));
8 u+ j% h3 ?( p! P; A - i = i + 1;
$ W( L# Q' M- }0 Y - }4 C4 A/ g9 @4 [3 k. D" @7 I
k4 @$ n& g. j# s4 P( [; N9 M4 H- b.CopyTo(outb, 0);4 f$ M3 k+ ^ h1 E u, }
' r" X ^. m7 N6 x( k- for (n = 0; n <= outlen - 8; n = n + 8)
. h6 }' F/ l: M: L, ? - {
. t/ O$ C6 N z8 u* d - for (i = 0; i < 8; i++) temp[i] = b[i + n];
6 L. S6 {0 G4 L% b) w* I0 K - DeCode(temp, outtemp, Key);. ~1 ^, M1 r' q% o2 m9 y
- for (i = 0; i < 8; i++) outb[i] = outtemp[i];7 r8 m D9 E9 N- i
- }
: C: F4 p$ t: {1 s* B' P - . C2 |0 n9 J: G2 n5 _" m4 D/ S* g
- c_str = new StringBuilder("", outlen);
/ ]' t* F4 z5 s' c3 z1 k - CopyByteToString(c_str, outb, outlen);- M4 E5 r J D
- return c_str.ToString();
8 \( j) H. M1 w
`* `, ^: U/ O# ~ E- }" \0 q* n+ i5 y# o8 T
- # L9 x7 E/ X v; `% j
# _( n- }" Q' h$ K- }
复制代码
) S* O2 X( E3 _2 n: x( [& t+ b( G% Y: X3 q% h
唯一锁写入Ukey: ( D, ?' x+ @9 ^0 T( Q Q2 e
8 H2 _, ]& ~& q% l( i, ^- N
公网客户端:安装插件
4 i1 _1 L: ^" c9 n# }. p C" _
多文件安装版+需要先插入UKEY
% f0 i) B" w) k6 C& d: R/ X 插入UKEY
5 L8 ]7 T1 ]0 k) `4 f% R 登录成功!
f! T6 G z3 n" E9 S% P( ] |
|