mirror of
https://github.com/klmp200/PQT_Gestionnaire_vente_stock.git
synced 2024-12-22 23:41:09 +00:00
Module Server, packg tools : création packg security; ajout clss IHashTool et MD5HashTool
This commit is contained in:
parent
dce4d4a4d2
commit
a6415ac494
@ -0,0 +1,5 @@
|
||||
package com.pqt.server.tools.security;
|
||||
|
||||
public interface IHashTool {
|
||||
String hashAndSalt(String str, String salt);
|
||||
}
|
@ -0,0 +1,30 @@
|
||||
package com.pqt.server.tools.security;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
public class MD5HashTool implements IHashTool{
|
||||
@Override
|
||||
public String hashAndSalt(String input, String salt) {
|
||||
String md5 = null;
|
||||
|
||||
if(input == null || salt == null) return null;
|
||||
|
||||
try {
|
||||
String str = salt+input;
|
||||
//Create MessageDigest object for MD5
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
|
||||
//Update input string in message digest
|
||||
digest.update(str.getBytes(), 0, str.length());
|
||||
|
||||
//Converts message digest value in base 16 (hex)
|
||||
md5 = new BigInteger(1, digest.digest()).toString(16);
|
||||
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return md5;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user