字段加密的问题
现在在做一个jsp页面,数据库用的是oracle,想在注册用户页面的时候把密码保存在user表中的password字段里,但想在此字段中显示的密码进行加密,请问这个应该怎么实现
------解决方案-------------------- import java.security.*;
public class MD5_ok {
public final static String MD5(String s) {
char hexDigits[] = { '0 ', '1 ', '2 ', '3 ', '4 ', '5 ', '6 ', '7 ', '8 ', '9 ',
'a ', 'b ', 'c ', 'd ', 'e ', 'f ' };
try {
byte[] strTemp = s.getBytes();
MessageDigest mdTemp = MessageDigest.getInstance( "MD5 ");
mdTemp.update(strTemp);
byte[] md = mdTemp.digest();
int j = md.length;
char str[] = new char[j * 2];
int k = 0;
for (int i = 0; i < j; i++) {
byte byte0 = md[i];
str[k++] = hexDigits[byte0 > > > 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
return new String(str);
} catch (Exception e) {
return null;
}
}
public static void main(String[] args) {
// MD5_Test aa = new MD5_Test();
System.out.print(MD5_ok.MD5( "gg "));
}
}
------解决方案--------------------接上:
private static void DES(byte Out[], byte In[], byte pSubKey[][], boolean Type) {
ByteToBit(M, In, 64);
Transform(M, M, IP_Table, 64);
if (Type == ENCRYPT) {
for (int i = 0; i < 16; ++i) {
byte Ri[] = new byte[32];
byte Li[] = new byte[32];
for (int j = 0; j < 32; j++) {
Ri[j] = tmp[j] = M[32 + j];
Li[j] = M[j];
}
F_func(Ri, pSubKey[i]);
Xor(Ri, Li, 32);
for (int j = 0; j < 32; j++) {
Li[j] = tmp[j];
}
for (int j = 0; j < 32; j++) {
M[32 + j] = Ri[j];
M[j] = Li[j];
}
}
} else {
for (int i = 15; i > = 0; --i) {
byte Ri[] = new byte[32];
byte Li[] = new byte[32];
for (int j = 0; j < 32; j++) {
Li[j] = tmp[j] = M[j];
Ri[j] = M[j + 32];
}
F_func(Li, pSubKey[i]);
Xor(Li, Ri, 32);
for (int j = 0; j < 32; j++) {
Ri[j] = tmp[j];
}
for (int j = 0; j < 32; j++) {
M[32 + j] = Ri[j];
M[j] = Li[j];
}
}
}
Transform(M, M, IPR_Table, 64);
BitToByte(Out, M, 64);
}
private static void SetSubKey(byte pSubKey[][], byte Key[]) {
ByteToBit(K, Key, 64);
Transform(K, K, PC1_Table, 56);
for (int i = 0; i < 16; ++i) {
RotateL(K, 28, LOOP_Table[i]);
byte b[] = new byte[36];
for (int j = 0; j < 36; j++) {
b[j] = K[28 + j];
}
RotateL(b, 28, LOOP_Table[i]);
for (int j = 0; j < 36; j++) {
K[28 + j] = b[j];
}
Transform(pSubKey[i], K, PC2_Table, 48);
}
}
private static void F_func(byte In[], byte Ki[]) {
Transform(MR, In, E_Table, 48);
Xor(MR, Ki, 48);
S_func(In, MR);
Transform(In, In, P_Table, 32);
}
private static void S_func(byte Out[], byte In[]) {
int in = 0, out = 0;
for (int i = 0, j, k; i < 8; ++i, in += 6, out += 4) {
j