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