feat: add static pepper
This commit is contained in:
parent
335ed0d893
commit
bb23e10689
@ -12,7 +12,6 @@ public class guesser {
|
|||||||
|
|
||||||
System.out.println("Hashed password");
|
System.out.println("Hashed password");
|
||||||
String hashed = hash.hashstring(randomPassword);
|
String hashed = hash.hashstring(randomPassword);
|
||||||
System.out.println(hashed);
|
|
||||||
|
|
||||||
System.out.println("Guessing...");
|
System.out.println("Guessing...");
|
||||||
long startTime = System.nanoTime();
|
long startTime = System.nanoTime();
|
||||||
@ -34,7 +33,7 @@ public class guesser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
System.out.println(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
18
hash.java
18
hash.java
@ -7,17 +7,23 @@ import java.security.NoSuchAlgorithmException;
|
|||||||
|
|
||||||
|
|
||||||
public class hash {
|
public class hash {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException, NoSuchAlgorithmException {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||||
System.out.println("Enter a string to hash: ");
|
System.out.println("Enter a string to hash: ");
|
||||||
String input = reader.readLine();
|
String input = reader.readLine();
|
||||||
|
String stored = hashstring(input);
|
||||||
|
|
||||||
System.out.println("Hashed as:");
|
System.out.println("Stored as:");
|
||||||
try {
|
System.out.println(stored);
|
||||||
System.out.println(hashstring(input));
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
System.out.println("Check password:");
|
||||||
System.out.println(e.toString());
|
String check = reader.readLine();
|
||||||
|
if (hashstring(check).equals(stored)) {
|
||||||
|
System.out.println("Match!");
|
||||||
|
} else {
|
||||||
|
System.out.println("No match!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String hashstring(String input) throws NoSuchAlgorithmException
|
public static String hashstring(String input) throws NoSuchAlgorithmException
|
||||||
|
@ -17,8 +17,6 @@ public class hashTable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Write to the file
|
// Write to the file
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < 1000000; i++) {
|
for (int i = 0; i < 1000000; i++) {
|
||||||
String randomPassword = guesser.getRandomPassword(i);
|
String randomPassword = guesser.getRandomPassword(i);
|
||||||
String hashed = hash.hashstring(randomPassword);
|
String hashed = hash.hashstring(randomPassword);
|
||||||
|
1000000
hashtable.txt
1000000
hashtable.txt
File diff suppressed because it is too large
Load Diff
@ -9,16 +9,15 @@ public class pepperedHash {
|
|||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||||
System.out.println("Enter a string to hash and salt: ");
|
System.out.println("Enter a string to hash and pepper: ");
|
||||||
String input = reader.readLine();
|
String input = reader.readLine();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String pepper = getPepper();
|
String pepper = getPepper();
|
||||||
System.out.println("Pepper is: " + pepper);
|
System.out.println("Pepper is: " + pepper);
|
||||||
// Remove starting 0s
|
|
||||||
|
|
||||||
String peppered = input + getPepper();
|
String peppered = input + getPepper();
|
||||||
System.out.println("Hashed as:");
|
System.out.println("Stored as:");
|
||||||
String hashed = hash.hashstring(peppered);
|
String hashed = hash.hashstring(peppered);
|
||||||
System.out.println(hashed);
|
System.out.println(hashed);
|
||||||
|
|
||||||
|
68
pepperedSaltedHash.java
Normal file
68
pepperedSaltedHash.java
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class pepperedSaltedHash {
|
||||||
|
public final static String alphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
System.out.println("Enter a string to hash, salt and pepper:");
|
||||||
|
String input = reader.readLine();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String salt = bytetohex.toHexString(saltedHash.getSalt());
|
||||||
|
while (salt.charAt(0) == '0') {
|
||||||
|
salt = salt.substring(1);
|
||||||
|
}
|
||||||
|
String pepper = getPepper();
|
||||||
|
System.out.println("Pepper is: " + pepper);
|
||||||
|
|
||||||
|
String saltedPeppered = input + salt + getPepper();
|
||||||
|
System.out.println("Stored as:");
|
||||||
|
String hashed = hash.hashstring(saltedPeppered);
|
||||||
|
String hashedWSalt = hashed + "$" + salt;
|
||||||
|
System.out.println(hashedWSalt);
|
||||||
|
|
||||||
|
System.out.println("Enter a string to check: ");
|
||||||
|
String check = reader.readLine();
|
||||||
|
String checkSalted = check + hashedWSalt.split("\\$")[1];
|
||||||
|
|
||||||
|
if (checkPeppered(checkSalted,hashed)){
|
||||||
|
System.out.println("Match!");
|
||||||
|
} else {
|
||||||
|
System.out.println("No match!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
System.out.println(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkPeppered(String check,String hashed) throws NoSuchAlgorithmException {
|
||||||
|
boolean match = false;
|
||||||
|
for (int i = 0; i<52;i++){
|
||||||
|
String pepperedCheck = check + alphabet.charAt(i);
|
||||||
|
String hashedCheck = hash.hashstring(pepperedCheck);
|
||||||
|
if (hashedCheck.equals(hashed)) {
|
||||||
|
match = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPepper() {
|
||||||
|
// Return random a-zA-Z
|
||||||
|
Random random = new Random();
|
||||||
|
int randomIndex = random.nextInt(52);
|
||||||
|
|
||||||
|
// Get the random character
|
||||||
|
char randomChar = alphabet.charAt(randomIndex);
|
||||||
|
return Character.toString(randomChar);
|
||||||
|
}
|
||||||
|
}
|
22
plainText.java
Normal file
22
plainText.java
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
|
||||||
|
public class plainText {
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
System.out.println("Enter a string to hash: ");
|
||||||
|
String input = reader.readLine();
|
||||||
|
|
||||||
|
System.out.println("Stored as:");
|
||||||
|
System.out.println(input);
|
||||||
|
|
||||||
|
System.out.println("Check password:");
|
||||||
|
String check = reader.readLine();
|
||||||
|
if (check.equals(input)) {
|
||||||
|
System.out.println("Match!");
|
||||||
|
} else {
|
||||||
|
System.out.println("No match!");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -18,7 +18,7 @@ public class saltedHash {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String salted = input + salt;
|
String salted = input + salt;
|
||||||
System.out.println("Hashed as:");
|
System.out.println("Stored as:");
|
||||||
String hashed = hash.hashstring(salted);
|
String hashed = hash.hashstring(salted);
|
||||||
String stored = hashed + "$"+salt;
|
String stored = hashed + "$"+salt;
|
||||||
System.out.println(stored);
|
System.out.println(stored);
|
||||||
|
71
staticPepperedSaltedHash.java
Normal file
71
staticPepperedSaltedHash.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.NetworkInterface;
|
||||||
|
import java.net.SocketException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class staticPepperedSaltedHash {
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IOException {
|
||||||
|
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
|
||||||
|
System.out.println("Enter a string to hash, salt and pepper:");
|
||||||
|
String input = reader.readLine();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String salt = bytetohex.toHexString(saltedHash.getSalt());
|
||||||
|
while (salt.charAt(0) == '0') {
|
||||||
|
salt = salt.substring(1);
|
||||||
|
}
|
||||||
|
String pepper = getPepper();
|
||||||
|
System.out.println("Pepper is: " + pepper);
|
||||||
|
|
||||||
|
String saltedPeppered = input + salt + getPepper();
|
||||||
|
System.out.println("Stored as:");
|
||||||
|
String hashed = hash.hashstring(saltedPeppered);
|
||||||
|
String hashedWSalt = hashed + "$" + salt;
|
||||||
|
System.out.println(hashedWSalt);
|
||||||
|
|
||||||
|
System.out.println("Enter a string to check: ");
|
||||||
|
String check = reader.readLine();
|
||||||
|
String checkSalted = check + hashedWSalt.split("\\$")[1];
|
||||||
|
|
||||||
|
if (checkPeppered(checkSalted,hashed)){
|
||||||
|
System.out.println("Match!");
|
||||||
|
} else {
|
||||||
|
System.out.println("No match!");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
System.out.println(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean checkPeppered(String check,String hashed) throws NoSuchAlgorithmException, SocketException {
|
||||||
|
boolean match = false;
|
||||||
|
String pepperedCheck = check + getPepper();
|
||||||
|
String hashedCheck = hash.hashstring(pepperedCheck);
|
||||||
|
if (hashedCheck.equals(hashed)) match = true;
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getPepper() throws SocketException {
|
||||||
|
Enumeration<NetworkInterface> nis = NetworkInterface.getNetworkInterfaces();
|
||||||
|
StringBuilder pepper = new StringBuilder();
|
||||||
|
while (nis.hasMoreElements()) {
|
||||||
|
NetworkInterface ni = nis.nextElement();
|
||||||
|
byte[] mac = ni.getHardwareAddress();
|
||||||
|
if (mac != null) {
|
||||||
|
for (int i = 0; i < mac.length; i++) {
|
||||||
|
pepper.append(String.format("%02X", mac[i]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return pepper.toString();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user