...
Code Block |
---|
import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; public final class HashExamples { private publicString staticsalt void main(String... aArgs) { try= "ia0942980234241sadfaewvo32"; //Randomly generated private void setPassword(String pass) { MessageDigest sha_1 = MessageDigest.getInstance("SHA-1"); byte[] hashOnehashVal = sha_1.digest("color"((pass+salt).getBytes()); //encode the string and salt log("Hash of 'color': " + hexEncode(hashOne));saveBytes(hashVal,"credentials.pw"); //save the hash value to credentials.pw } private boolean checkPassword(String pass) throws Exception { MessageDigest sha.reset(sha_1 = MessageDigest.getInstance("SHA-1"); byte[] hashTwohashVal1 = sha_1.digest("colour"((pass+salt).getBytes()); //encode the string and log("Hash of 'colour': " + hexEncode(hashTwo)); } catch (NoSuchAlgorithmException ex){salt byte[] hashVal2 = loadBytes("credentials.pw"); //load the hash value stored in credentials.pw return log("No such algorithm found in JRE."); }Arrays.equals(hashVal1, hashVal2); } } |