Bladeren bron

1.添加锁定解除接口数据处理

20241218TB223FC(测试jar包)
wangwanlei 10 maanden geleden
bovenliggende
commit
f430a3608b

+ 1
- 1
app/src/main/java/com/xhly/manageapp/network/UriAdress.kt Bestand weergeven

@@ -93,7 +93,7 @@ object UriAdress {
93 93
     /**
94 94
      * 解除当前锁屏
95 95
      */
96
-    const val PWD_DEATIL_USERPAD = "/password/detail_userpad"
96
+   /* const val PWD_DEATIL_USERPAD = "/password/detail_userpad"*/
97 97
 
98 98
     /**
99 99
      * 修改密码

+ 6
- 5
app/src/main/java/com/xhly/manageapp/ui/login/activity/LoginActivity.kt Bestand weergeven

@@ -72,8 +72,11 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
72 72
             Toast(getString(R.string.syncsucess))
73 73
         }
74 74
         viewModel.controlResultData.observe(this){
75
+            //为真则可以进入管理页面
75 76
             if (it){
76 77
                 startIntentActivity(ManageActivity().javaClass)
78
+            }else{
79
+                Toast(getString(R.string.codeerror))
77 80
             }
78 81
         }
79 82
         val exitControlFlag = currentSpUtils.getParam(Const.EXIT_CONTROL, false) as Boolean
@@ -383,15 +386,13 @@ class LoginActivity : BaseActivity<LoginViewModel, ActivityLoginBinding>() {
383 386
                     val cancelTv = v.findViewById<TextView>(R.id.dialog_cancel_tv)
384 387
                     val editText = v.findViewById<EditText>(R.id.dialog_et)
385 388
                     editText.hint = getString(R.string.inputcode)
386
-                    titleTv.text = getString(R.string.exitcontrol)
389
+                    titleTv.text = getString(R.string.checkcode)
387 390
                     enterTv.setOnClickListener {
388 391
                         val code = editText.text
389 392
                         if ((!code.isNullOrBlank()) && code.length >= 6) {
390 393
                             dialog.dismiss()
391
-                            try {
392
-                                viewModel.postExitControl(code.toString())
393
-                            } catch (e: Exception) {
394
-
394
+                            ManageApplication.getDeviceInfo()?.let {sn->
395
+                                viewModel.postExitControl(code.toString(),sn)
395 396
                             }
396 397
                         }
397 398
                     }

+ 6
- 7
app/src/main/java/com/xhly/manageapp/ui/login/netservice/LoginService.kt Bestand weergeven

@@ -2,7 +2,6 @@ package com.xhly.manageapp.ui.login.netservice
2 2
 
3 3
 import com.xhly.corelib.network.bean.ResponseData
4 4
 import com.xhly.manageapp.bean.login.CheckLoginBean
5
-import com.xhly.manageapp.bean.login.CodeDetailBean
6 5
 import com.xhly.manageapp.bean.login.LoginBean
7 6
 import com.xhly.manageapp.bean.user.UserBean
8 7
 import com.xhly.manageapp.network.UriAdress
@@ -32,8 +31,8 @@ interface LoginService {
32 31
     /**
33 32
      * 解除当前锁屏
34 33
      */
35
-    @POST(UriAdress.PWD_DEATIL_USERPAD)
36
-    suspend fun postPwdDetail(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>
34
+/*    @POST(UriAdress.PWD_DEATIL_USERPAD)
35
+    suspend fun postPwdDetail(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>*/
37 36
 
38 37
     /**
39 38
      * 修改密码 userid用户id loginpwd新密码 oldpwd原密码
@@ -48,10 +47,10 @@ interface LoginService {
48 47
     suspend fun postSyncTime():ResponseData<Long>
49 48
 
50 49
     /**
51
-     * 退出管控调用这个接口,参数password
50
+     * 解除当前锁屏,以及进入管理页面
52 51
      */
53 52
     @POST(UriAdress.EXIT_CONTROL)
54
-    suspend fun postExitControl(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>
53
+    suspend fun postExitControl(@Body map:HashMap<String,Any>):ResponseData<Any>
55 54
 
56 55
     /**
57 56
      * 违规事件发送socket消息后,请求接口然后处理锁定
@@ -59,7 +58,7 @@ interface LoginService {
59 58
      *  pushType  3锁定
60 59
      */
61 60
     @POST(UriAdress.EDIT_LOCKED)
62
-    suspend fun postExitLocked(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>
61
+    suspend fun postExitLocked(@Body map:HashMap<String,Any>):ResponseData<Any>
63 62
 
64 63
     /**
65 64
      * 违规事件发送socket消息后,请求接口然后处理恢复出厂设置
@@ -67,5 +66,5 @@ interface LoginService {
67 66
      * pushType  6恢复出厂设置
68 67
      */
69 68
     @POST(UriAdress.EDIT_RESETED)
70
-    suspend fun postExitReseted(@Body map:HashMap<String,Any>):ResponseData<CodeDetailBean>
69
+    suspend fun postExitReseted(@Body map:HashMap<String,Any>):ResponseData<Any>
71 70
 }

+ 26
- 25
app/src/main/java/com/xhly/manageapp/viewmodel/BaseViewModel.kt Bestand weergeven

@@ -4,6 +4,7 @@ import androidx.lifecycle.LiveData
4 4
 import androidx.lifecycle.MutableLiveData
5 5
 import com.xhly.corelib.base.viewmodel.CommonBaseViewModel
6 6
 import com.xhly.corelib.network.RetrofitService
7
+import com.xhly.corelib.utils.MD5Utils
7 8
 import com.xhly.manageapp.bean.log.LogPushBean
8 9
 import com.xhly.manageapp.bean.log.LogdOperateBean
9 10
 import com.xhly.manageapp.network.log.LogService
@@ -28,17 +29,34 @@ open class BaseViewModel : CommonBaseViewModel() {
28 29
      */
29 30
     fun postPwdDetail(code: String, sn: String) {
30 31
         launchUI {
31
-            val map = HashMap<String, Any>()
32
-            map["sn"] = sn
33
-            val result = loginService.postPwdDetail(map)
34
-            if (result.code == 0) {
35
-                pwdResult.value = result.obj.controlPwd.equals(code)
36
-            } else {
37
-                pwdResult.value = false
32
+            //先对比本地密码,一致则直接解锁,不然传给服务器
33
+            if (code == MD5Utils.getDynamicPassword(sn)){
34
+                pwdResult.value =true
35
+            }else{
36
+                val map = HashMap<String, Any>()
37
+                map["password"] = code
38
+                val result=loginService.postExitControl(map)
39
+                pwdResult.value = result.code == 0
38 40
             }
39 41
         }
40 42
     }
41 43
 
44
+    /**
45
+     * 手动进入管理页面
46
+     */
47
+    fun postExitControl(code:String,sn: String){
48
+        launchUI {
49
+            //先对比本地密码,一致则可以进入本地管理页面
50
+            controlResult.value = code == MD5Utils.getDynamicPassword(sn)
51
+            /*else{
52
+                val map=HashMap<String,Any>()
53
+                map["password"]=code
54
+                val result= loginService.postExitControl(map)
55
+                controlResult.value = result.code==0
56
+            }*/
57
+        }
58
+    }
59
+
42 60
     /**
43 61
      * 发送事件日志
44 62
      */
@@ -74,24 +92,7 @@ open class BaseViewModel : CommonBaseViewModel() {
74 92
             }
75 93
         }
76 94
     }
77
-    /**
78
-     * 手动退出管控
79
-     */
80
-    fun postExitControl(password:String){
81
-        launchUI {
82
-            val map=HashMap<String,Any>()
83
-            map["password"]=password
84
-            val result= loginService.postExitControl(map)
85
-            if (result.code==0){
86
-                val codeDetailBean = result.obj
87
-                controlResult.value = password==codeDetailBean.controlPwd
88
-            }else{
89
-                if (!result.msg.isNullOrEmpty()){
90
-                    netMessage.value=result.msg
91
-                }
92
-            }
93
-        }
94
-    }
95
+
95 96
 
96 97
     /**
97 98
      * 违规事件发送socket消息后,请求接口然后处理锁定

+ 1
- 0
app/src/main/res/values/strings.xml Bestand weergeven

@@ -43,4 +43,5 @@
43 43
     <string name="exitcontrol">解除管控</string>
44 44
     <string name="updatestrategy">更新策略</string>
45 45
     <string name="updatetips">开始请求策略</string>
46
+    <string name="checkcode">密码校验</string>
46 47
 </resources>

+ 423
- 0
corelib/src/main/java/com/xhly/corelib/utils/MD5.java Bestand weergeven

@@ -0,0 +1,423 @@
1
+package com.xhly.corelib.utils;
2
+
3
+
4
+
5
+import java.security.MessageDigest;
6
+import java.security.NoSuchAlgorithmException;
7
+
8
+/************************************************
9
+ MD5 算法的Java Bean
10
+ *************************************************/
11
+
12
+public class MD5 {
13
+
14
+    /*
15
+     * 下面这些S11-S44实际上是一个4*4的矩阵,在原始的C实现中是用#define 实现的, 这里把它们实现成为static
16
+     * final是表示了只读,切能在同一个进程空间内的多个 Instance间共享
17
+     */
18
+    static final int S11 = 7;
19
+
20
+    static final int S12 = 12;
21
+
22
+    static final int S13 = 17;
23
+
24
+    static final int S14 = 22;
25
+
26
+    static final int S21 = 5;
27
+
28
+    static final int S22 = 9;
29
+
30
+    static final int S23 = 14;
31
+
32
+    static final int S24 = 20;
33
+
34
+    static final int S31 = 4;
35
+
36
+    static final int S32 = 11;
37
+
38
+    static final int S33 = 16;
39
+
40
+    static final int S34 = 23;
41
+
42
+    static final int S41 = 6;
43
+
44
+    static final int S42 = 10;
45
+
46
+    static final int S43 = 15;
47
+
48
+    static final int S44 = 21;
49
+
50
+    static final byte[] PADDING = {-128, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
51
+            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
52
+            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
53
+            0, 0, 0, 0, 0, 0, 0};
54
+
55
+    /*
56
+     * 下面的三个成员是MD5计算过程中用到的3个核心数据,在原始的C实现中 被定义到MD5_CTX结构中
57
+     */
58
+    private final long[] state = new long[4]; // state (ABCD)
59
+
60
+    private final long[] count = new long[2]; // number of bits, modulo 2^64 (lsb
61
+
62
+    private final byte[] buffer = new byte[64]; // input buffer
63
+
64
+    /*
65
+     * digestHexStr是MD5的唯一一个公共成员,是最新一次计算结果的 16进制ASCII表示.
66
+     */
67
+    public String digestHexStr;
68
+
69
+    /*
70
+     * digest,是最新一次计算结果的2进制内部表示,表示128bit的MD5值.
71
+     */
72
+    private final byte[] digest = new byte[16];
73
+
74
+    /*
75
+     * getMD5ofStr是类MD5最主要的公共方法,入口参数是你想要进行MD5变换的字符串
76
+     * 返回的是变换完的结果,这个结果是从公共成员digestHexStr取得的.
77
+     */
78
+    public String getMD5ofStr(String inbuf) {
79
+        md5Init();
80
+        md5Update(inbuf.getBytes(), inbuf.length());
81
+        md5Final();
82
+
83
+        digestHexStr = "";
84
+        for (int i = 0; i < 16; i++) {
85
+            digestHexStr += byteHEX(digest[i]);
86
+        }
87
+
88
+        return digestHexStr;
89
+    }
90
+
91
+    /**
92
+     * 获取加密后的32位小写字符串
93
+     * @Param [str]
94
+     * @Author ywx
95
+     * @Date 2020/12/11 16:02
96
+     * @Return java.lang.String
97
+     **/
98
+    public String getMD5ofStr2(String str) {
99
+        return getMD5ofStr(str).toLowerCase();
100
+    }
101
+
102
+    // 这是MD5这个类的标准构造函数,JavaBean要求有一个public的并且没有参数的构造函数
103
+    public MD5() {
104
+        md5Init();
105
+        return;
106
+    }
107
+
108
+    /* md5Init是一个初始化函数,初始化核心变量,装入标准的幻数 */
109
+    private void md5Init() {
110
+        count[0] = 0L;
111
+        count[1] = 0L;
112
+        // /* Load magic initialization constants.
113
+
114
+        state[0] = 0x67452301L;
115
+        state[1] = 0xefcdab89L;
116
+        state[2] = 0x98badcfeL;
117
+        state[3] = 0x10325476L;
118
+
119
+        return;
120
+    }
121
+
122
+    /*
123
+     * F, G, H ,I 是4个基本的MD5函数,在原始的MD5的C实现中,由于它们是
124
+     * 简单的位运算,可能出于效率的考虑把它们实现成了宏,在java中,我们把它们 实现成了private方法,名字保持了原来C中的。
125
+     */
126
+
127
+    private long F(long x, long y, long z) {
128
+        return (x & y) | ((~x) & z);
129
+
130
+    }
131
+
132
+    private long G(long x, long y, long z) {
133
+        return (x & z) | (y & (~z));
134
+
135
+    }
136
+
137
+    private long H(long x, long y, long z) {
138
+        return x ^ y ^ z;
139
+    }
140
+
141
+    private long I(long x, long y, long z) {
142
+        return y ^ (x | (~z));
143
+    }
144
+
145
+    /*
146
+     * FF,GG,HH和II将调用F,G,H,I进行近一步变换 FF, GG, HH, and II transformations for
147
+     * rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent
148
+     * recomputation.
149
+     */
150
+
151
+    private long FF(long a, long b, long c, long d, long x, long s, long ac) {
152
+        a += F(b, c, d) + x + ac;
153
+        a = ((int) a << s) | ((int) a >>> (32 - s));
154
+        a += b;
155
+        return a;
156
+    }
157
+
158
+    private long GG(long a, long b, long c, long d, long x, long s, long ac) {
159
+        a += G(b, c, d) + x + ac;
160
+        a = ((int) a << s) | ((int) a >>> (32 - s));
161
+        a += b;
162
+        return a;
163
+    }
164
+
165
+    private long HH(long a, long b, long c, long d, long x, long s, long ac) {
166
+        a += H(b, c, d) + x + ac;
167
+        a = ((int) a << s) | ((int) a >>> (32 - s));
168
+        a += b;
169
+        return a;
170
+    }
171
+
172
+    private long II(long a, long b, long c, long d, long x, long s, long ac) {
173
+        a += I(b, c, d) + x + ac;
174
+        a = ((int) a << s) | ((int) a >>> (32 - s));
175
+        a += b;
176
+        return a;
177
+    }
178
+
179
+    /*
180
+     * md5Update是MD5的主计算过程,inbuf是要变换的字节串,inputlen是长度,这个
181
+     * 函数由getMD5ofStr调用,调用之前需要调用md5init,因此把它设计成private的
182
+     */
183
+    private void md5Update(byte[] inbuf, int inputLen) {
184
+
185
+        int i, index, partLen;
186
+        byte[] block = new byte[64];
187
+        index = (int) (count[0] >>> 3) & 0x3F;
188
+        // /* Update number of bits */
189
+        if ((count[0] += (inputLen << 3)) < (inputLen << 3))
190
+            count[1]++;
191
+        count[1] += (inputLen >>> 29);
192
+
193
+        partLen = 64 - index;
194
+
195
+        // Transform as many times as possible.
196
+        if (inputLen >= partLen) {
197
+            md5Memcpy(buffer, inbuf, index, 0, partLen);
198
+            md5Transform(buffer);
199
+
200
+            for (i = partLen; i + 63 < inputLen; i += 64) {
201
+
202
+                md5Memcpy(block, inbuf, 0, i, 64);
203
+                md5Transform(block);
204
+            }
205
+            index = 0;
206
+
207
+        } else
208
+
209
+            i = 0;
210
+
211
+        // /* Buffer remaining input */
212
+        md5Memcpy(buffer, inbuf, index, i, inputLen - i);
213
+    }
214
+
215
+    /*
216
+     * md5Final整理和填写输出结果
217
+     */
218
+    private void md5Final() {
219
+        byte[] bits = new byte[8];
220
+        int index, padLen;
221
+
222
+        // /* Save number of bits */
223
+        Encode(bits, count, 8);
224
+
225
+        // /* Pad out to 56 mod 64.
226
+        index = (int) (count[0] >>> 3) & 0x3f;
227
+        padLen = (index < 56) ? (56 - index) : (120 - index);
228
+        md5Update(PADDING, padLen);
229
+
230
+        // /* Append length (before padding) */
231
+        md5Update(bits, 8);
232
+
233
+        // /* Store state in digest */
234
+        Encode(digest, state, 16);
235
+    }
236
+
237
+    /*
238
+     * md5Memcpy是一个内部使用的byte数组的块拷贝函数,从input的inpos开始把len长度的
239
+     * 字节拷贝到output的outpos位置开始
240
+     */
241
+
242
+    private void md5Memcpy(byte[] output, byte[] input, int outpos, int inpos,
243
+                           int len) {
244
+        int i;
245
+
246
+        for (i = 0; i < len; i++)
247
+            output[outpos + i] = input[inpos + i];
248
+    }
249
+
250
+    /*
251
+     * md5Transform是MD5核心变换程序,有md5Update调用,block是分块的原始字节
252
+     */
253
+    private void md5Transform(byte block[]) {
254
+        long a = state[0], b = state[1], c = state[2], d = state[3];
255
+        long[] x = new long[16];
256
+
257
+        Decode(x, block, 64);
258
+
259
+        /* Round 1 */
260
+        a = FF(a, b, c, d, x[0], S11, 0xd76aa478L); /* 1 */
261
+        d = FF(d, a, b, c, x[1], S12, 0xe8c7b756L); /* 2 */
262
+        c = FF(c, d, a, b, x[2], S13, 0x242070dbL); /* 3 */
263
+        b = FF(b, c, d, a, x[3], S14, 0xc1bdceeeL); /* 4 */
264
+        a = FF(a, b, c, d, x[4], S11, 0xf57c0fafL); /* 5 */
265
+        d = FF(d, a, b, c, x[5], S12, 0x4787c62aL); /* 6 */
266
+        c = FF(c, d, a, b, x[6], S13, 0xa8304613L); /* 7 */
267
+        b = FF(b, c, d, a, x[7], S14, 0xfd469501L); /* 8 */
268
+        a = FF(a, b, c, d, x[8], S11, 0x698098d8L); /* 9 */
269
+        d = FF(d, a, b, c, x[9], S12, 0x8b44f7afL); /* 10 */
270
+        c = FF(c, d, a, b, x[10], S13, 0xffff5bb1L); /* 11 */
271
+        b = FF(b, c, d, a, x[11], S14, 0x895cd7beL); /* 12 */
272
+        a = FF(a, b, c, d, x[12], S11, 0x6b901122L); /* 13 */
273
+        d = FF(d, a, b, c, x[13], S12, 0xfd987193L); /* 14 */
274
+        c = FF(c, d, a, b, x[14], S13, 0xa679438eL); /* 15 */
275
+        b = FF(b, c, d, a, x[15], S14, 0x49b40821L); /* 16 */
276
+
277
+        /* Round 2 */
278
+        a = GG(a, b, c, d, x[1], S21, 0xf61e2562L); /* 17 */
279
+        d = GG(d, a, b, c, x[6], S22, 0xc040b340L); /* 18 */
280
+        c = GG(c, d, a, b, x[11], S23, 0x265e5a51L); /* 19 */
281
+        b = GG(b, c, d, a, x[0], S24, 0xe9b6c7aaL); /* 20 */
282
+        a = GG(a, b, c, d, x[5], S21, 0xd62f105dL); /* 21 */
283
+        d = GG(d, a, b, c, x[10], S22, 0x2441453L); /* 22 */
284
+        c = GG(c, d, a, b, x[15], S23, 0xd8a1e681L); /* 23 */
285
+        b = GG(b, c, d, a, x[4], S24, 0xe7d3fbc8L); /* 24 */
286
+        a = GG(a, b, c, d, x[9], S21, 0x21e1cde6L); /* 25 */
287
+        d = GG(d, a, b, c, x[14], S22, 0xc33707d6L); /* 26 */
288
+        c = GG(c, d, a, b, x[3], S23, 0xf4d50d87L); /* 27 */
289
+        b = GG(b, c, d, a, x[8], S24, 0x455a14edL); /* 28 */
290
+        a = GG(a, b, c, d, x[13], S21, 0xa9e3e905L); /* 29 */
291
+        d = GG(d, a, b, c, x[2], S22, 0xfcefa3f8L); /* 30 */
292
+        c = GG(c, d, a, b, x[7], S23, 0x676f02d9L); /* 31 */
293
+        b = GG(b, c, d, a, x[12], S24, 0x8d2a4c8aL); /* 32 */
294
+
295
+        /* Round 3 */
296
+        a = HH(a, b, c, d, x[5], S31, 0xfffa3942L); /* 33 */
297
+        d = HH(d, a, b, c, x[8], S32, 0x8771f681L); /* 34 */
298
+        c = HH(c, d, a, b, x[11], S33, 0x6d9d6122L); /* 35 */
299
+        b = HH(b, c, d, a, x[14], S34, 0xfde5380cL); /* 36 */
300
+        a = HH(a, b, c, d, x[1], S31, 0xa4beea44L); /* 37 */
301
+        d = HH(d, a, b, c, x[4], S32, 0x4bdecfa9L); /* 38 */
302
+        c = HH(c, d, a, b, x[7], S33, 0xf6bb4b60L); /* 39 */
303
+        b = HH(b, c, d, a, x[10], S34, 0xbebfbc70L); /* 40 */
304
+        a = HH(a, b, c, d, x[13], S31, 0x289b7ec6L); /* 41 */
305
+        d = HH(d, a, b, c, x[0], S32, 0xeaa127faL); /* 42 */
306
+        c = HH(c, d, a, b, x[3], S33, 0xd4ef3085L); /* 43 */
307
+        b = HH(b, c, d, a, x[6], S34, 0x4881d05L); /* 44 */
308
+        a = HH(a, b, c, d, x[9], S31, 0xd9d4d039L); /* 45 */
309
+        d = HH(d, a, b, c, x[12], S32, 0xe6db99e5L); /* 46 */
310
+        c = HH(c, d, a, b, x[15], S33, 0x1fa27cf8L); /* 47 */
311
+        b = HH(b, c, d, a, x[2], S34, 0xc4ac5665L); /* 48 */
312
+
313
+        /* Round 4 */
314
+        a = II(a, b, c, d, x[0], S41, 0xf4292244L); /* 49 */
315
+        d = II(d, a, b, c, x[7], S42, 0x432aff97L); /* 50 */
316
+        c = II(c, d, a, b, x[14], S43, 0xab9423a7L); /* 51 */
317
+        b = II(b, c, d, a, x[5], S44, 0xfc93a039L); /* 52 */
318
+        a = II(a, b, c, d, x[12], S41, 0x655b59c3L); /* 53 */
319
+        d = II(d, a, b, c, x[3], S42, 0x8f0ccc92L); /* 54 */
320
+        c = II(c, d, a, b, x[10], S43, 0xffeff47dL); /* 55 */
321
+        b = II(b, c, d, a, x[1], S44, 0x85845dd1L); /* 56 */
322
+        a = II(a, b, c, d, x[8], S41, 0x6fa87e4fL); /* 57 */
323
+        d = II(d, a, b, c, x[15], S42, 0xfe2ce6e0L); /* 58 */
324
+        c = II(c, d, a, b, x[6], S43, 0xa3014314L); /* 59 */
325
+        b = II(b, c, d, a, x[13], S44, 0x4e0811a1L); /* 60 */
326
+        a = II(a, b, c, d, x[4], S41, 0xf7537e82L); /* 61 */
327
+        d = II(d, a, b, c, x[11], S42, 0xbd3af235L); /* 62 */
328
+        c = II(c, d, a, b, x[2], S43, 0x2ad7d2bbL); /* 63 */
329
+        b = II(b, c, d, a, x[9], S44, 0xeb86d391L); /* 64 */
330
+
331
+        state[0] += a;
332
+        state[1] += b;
333
+        state[2] += c;
334
+        state[3] += d;
335
+    }
336
+
337
+    /*
338
+     * Encode把long数组按顺序拆成byte数组,因为java的long类型是64bit的, 只拆低32bit,以适应原始C实现的用途
339
+     */
340
+    private void Encode(byte[] output, long[] input, int len) {
341
+        int i, j;
342
+
343
+        for (i = 0, j = 0; j < len; i++, j += 4) {
344
+            output[j] = (byte) (input[i] & 0xffL);
345
+            output[j + 1] = (byte) ((input[i] >>> 8) & 0xffL);
346
+            output[j + 2] = (byte) ((input[i] >>> 16) & 0xffL);
347
+            output[j + 3] = (byte) ((input[i] >>> 24) & 0xffL);
348
+        }
349
+    }
350
+
351
+    /*
352
+     * Decode把byte数组按顺序合成成long数组,因为java的long类型是64bit的,
353
+     * 只合成低32bit,高32bit清零,以适应原始C实现的用途
354
+     */
355
+    private void Decode(long[] output, byte[] input, int len) {
356
+        int i, j;
357
+
358
+        for (i = 0, j = 0; j < len; i++, j += 4)
359
+            output[i] = b2iu(input[j]) | (b2iu(input[j + 1]) << 8)
360
+                    | (b2iu(input[j + 2]) << 16) | (b2iu(input[j + 3]) << 24);
361
+
362
+        return;
363
+    }
364
+
365
+    /*
366
+     * b2iu是我写的一个把byte按照不考虑正负号的原则的"升位"程序,因为java没有unsigned运算
367
+     */
368
+    public static long b2iu(byte b) {
369
+        return b < 0 ? b & 0x7F + 128 : b;
370
+    }
371
+
372
+    /*
373
+     * byteHEX(),用来把一个byte类型的数转换成十六进制的ASCII表示,
374
+     * 因为java中的byte的toString无法实现这一点,我们又没有C语言中的 sprintf(outbuf,"%02X",ib)
375
+     */
376
+    public static String byteHEX(byte ib) {
377
+        char[] Digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A',
378
+                'B', 'C', 'D', 'E', 'F'};
379
+        char[] ob = new char[2];
380
+        ob[0] = Digit[(ib >>> 4) & 0X0F];
381
+        ob[1] = Digit[ib & 0X0F];
382
+        String s = new String(ob);
383
+        return s;
384
+    }
385
+
386
+    /**
387
+     * js-md5加密用户密码
388
+     */
389
+    public String getJsMD5(String password) {
390
+        try {
391
+            // 得到一个信息摘要器
392
+            MessageDigest digest = MessageDigest.getInstance("md5");
393
+            byte[] result = digest.digest(password.getBytes());
394
+            StringBuffer buffer = new StringBuffer();
395
+            // 把没一个byte 做一个与运算 0xff;
396
+            for (byte b : result) {
397
+                // 与运算
398
+                int number = b & 0xff;// 加盐
399
+                String str = Integer.toHexString(number);
400
+                if (str.length() == 1) {
401
+                    buffer.append("0");
402
+                }
403
+                buffer.append(str);
404
+            }
405
+
406
+            // 标准的md5加密后的结果
407
+            return buffer.toString();
408
+        } catch (NoSuchAlgorithmException e) {
409
+            e.printStackTrace();
410
+            return "";
411
+        }
412
+    }
413
+
414
+    public static void main(String args[]) {
415
+        MD5 m = new MD5();
416
+        String str = "123456";
417
+        str = m.getMD5ofStr(str);
418
+        System.out.println(str);
419
+
420
+
421
+    }
422
+
423
+}

+ 25
- 0
corelib/src/main/java/com/xhly/corelib/utils/MD5Utils.java Bestand weergeven

@@ -6,6 +6,8 @@ package com.xhly.corelib.utils;
6 6
 
7 7
 import java.security.MessageDigest;
8 8
 import java.security.NoSuchAlgorithmException;
9
+import java.text.SimpleDateFormat;
10
+import java.util.Date;
9 11
 
10 12
 /**
11 13
  *@Description: 将字符串转化为MD5
@@ -65,4 +67,27 @@ public class MD5Utils {
65 67
             return "";
66 68
         }
67 69
     }
70
+
71
+    //获得锁定密码
72
+    public static String getDynamicPassword(String sn) {
73
+        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHH");
74
+        String format = dateFormat.format(System.currentTimeMillis());
75
+        String pwd = sn + format;
76
+        MD5 md5 = new MD5();
77
+        pwd = md5.getMD5ofStr(pwd);// md5加密
78
+        pwd = pwd.substring(pwd.length() - 8);
79
+        StringBuilder sb = new StringBuilder();
80
+        for (int i = 0; i < 8; i++) {
81
+            char c = pwd.charAt(i);
82
+            if (Character.isLetter(c)) {
83
+                int lastDigit = (int) c % 10;
84
+                sb.append(lastDigit);
85
+            } else {
86
+                sb.append(c);
87
+            }
88
+        }
89
+
90
+        return sb.toString();
91
+    }
92
+
68 93
 }

Laden…
Annuleren
Opslaan