-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtestdata.file
More file actions
84 lines (70 loc) · 2 KB
/
testdata.file
File metadata and controls
84 lines (70 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package com.singam;x
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Message {
public static final int ACKSESSION = 0;
public static final int READY = 1;
public static final int SIGNED = 2;
public static final int PKEY = 3;
public static final int SESSION = 4;
public static final int AUTH = 5;
public static final int NOT_READY = 6;
public static final int CHAT = 7;
public static final int INIT = 8;
private int id = 0;
private String msg = "";
private String sign = null;
public Message(int id,String msg){
this.msg = msg;
this.id = id;
}
public Message(int id,String msg, String sign){
this.msg = msg;
this.id = id;
this.sign = sign;
}
public void sign(String session){
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
this.sign = new String(md.digest((session + this.msg + session).getBytes()));
}
public String getMsg(){
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public int getId(){
return id;
}
public String getSign(){
return sign;
}
public String packTo(boolean sign){
String packed = "";
if(sign){
packed = packed+id+" "+sign+" "+msg;
}else{
packed = packed+id+" "+msg;
}
return packed;
}
public boolean verify(String session){
boolean verified = false;
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
String sign2 = new String(md.digest((session + this.msg + session).getBytes()));
if(sign2.compareTo(this.sign)== 0){
verified = true;
}
return verified;
}
}