2024年4月28日发(作者:)
101
*/
102
public
static
String getMd5String32(String str) throws
NoSuchAlgorithmException {
103
MessageDigest md = tance("MD5");
104
(es());
105
byte
b[] = ();
106
int
i;
107
StringBuffer buf = new
StringBuffer();
108
for
(int
offset = 0; offset < ; offset++) {
109
i = b[offset];
110
if
(i < 0)
111
i += 256;
112
113
if
(i < 16)
114
("0");
115
116
(tring(i));
117
}
118
return
ng();
119
}
120
/**
121
* 获取MD5密码
122
* @param password
123
* @param salt
124
* @return
* @throws NoSuchAlgorithmException
125
*/
126
public
static
String getMD5Pwd(String password, String salt) throws
NoSuchAlgorithmException {
127
String result = null;
128
if
(lank(salt)) {
129
result = getMD5(getMD5(password) + salt);
130
} else
{
131
result = getMD5(password);
}
132
return
result;
133
}
134
135
/**
136
* 获取MD5加密数据
137
* @param input
* @return
138
* @throws NoSuchAlgorithmException
139
*/
140
public
static
String getMD5(String input) throws
NoSuchAlgorithmException {
141
String result = input;
142
if
(input != null) {
143
MessageDigest md = tance("MD5"); //or "SHA-1"
144
(es());
BigInteger hash = new
BigInteger(1, ());
145
146
result = ng(16);
147
while
(() < 32) {//40 for SHA-1
148
result = "0"
+ result;
149
}
}
150
return
result;
151
}
152
153
/**
154
* For test by Jason
155
*/
156
public
static
void
main(String[] args) {
157
try
{
n(getMd5String16("Jason")); //829018f9dbd65fb8
158
} catch
(NoSuchAlgorithmException e) {
159
tackTrace();
160
}
161
}
162
}
163
164
165
166
167
168
169
发布评论