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