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
| Main
UserCount uc = new UserCount();
System.out.println("Entrez le password:");
BufferedReader entreePw = BufferedReader(new InputStreamReader(System.in));
uc.setPw(hashThis(entreePw.readLine()));
try {
FileOutputStream fichier = new FileOutputStream("c:/tmp/user.serial");
ObjectOutputStream oos = new ObjectOutputStream(fichier);
oos.writeObject(bc);
oos.flush();
oos.close();
public String hashThis(String pwdClair) throws NoSuchAlgorithmException {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(mdpClair.getBytes());
byte[] md5 = md.digest();
String mdpCrypte = "";
for (int i=0; i< md5.length; i++) {
mdpCrypte += md5[i];
}
return mdpCrypte;
}
______________________________________________
class UserCount
private byte[] userPw;
public UserCount() {
}
public void setPw(final byte[] pw){userPw = pw;}
public byte[] getPw(){return userPw;} |