Created
September 21, 2014 15:27
-
-
Save iamedu/cf129ab027785bed8dc2 to your computer and use it in GitHub Desktop.
Check phone service
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.security.* | |
class PhoneHasherService { | |
String checkHashPhone(String phone, String hash) { | |
int iterations = 128 | |
String [] hashParts = hash.split(":") | |
byte[] salt = Base64.getDecoder().decode(hashParts[1]) | |
byte[] hashedPassword = getHash(iterations, phone, salt) | |
String hashedPasswordString = Base64.getEncoder().encodeToString(hashedPassword) | |
hashedPasswordString + ":" + hashParts[1] | |
} | |
public byte[] getHash(int iterationNb, String password, byte[] salt) { | |
MessageDigest digest = MessageDigest.getInstance("SHA-1"); | |
digest.reset(); | |
digest.update(salt); | |
byte[] input = digest.digest(password.getBytes("UTF-8")); | |
for (int i = 0; i < iterationNb; i++) { | |
digest.reset(); | |
input = digest.digest(input); | |
} | |
return input; | |
} | |
} | |
PhoneHasherService service = new PhoneHasherService() | |
println service.checkHashPhone("234235", "0+eMYWNBzhcjL2x9IjpVsOxMGVs=:6PcU2iH6O17PKFR2bpVzW8D/wZ6jVQwdzAOS1I88210=") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment