Skip to content

Commit 86d517e

Browse files
committed
add SHA Hash externe
1 parent 72acf72 commit 86d517e

4 files changed

Lines changed: 142 additions & 0 deletions

File tree

dev/HASH_generator/SHAHash.class

2.56 KB
Binary file not shown.

dev/HASH_generator/SHAHash.java

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import java.nio.charset.StandardCharsets;
2+
import java.security.MessageDigest;
3+
import java.security.NoSuchAlgorithmException;
4+
5+
public class SHAHash {
6+
7+
/**
8+
* It is the same domain as the class 'SHAHash.java' from the app.
9+
*/
10+
public static final String DOMAIN = "com.aristy.gogocar";
11+
12+
/**
13+
* Main method
14+
* @param args
15+
*/
16+
public static void main(String[] args){
17+
if (args.length < 1) {
18+
System.out.println("Need an argument. abord. ");
19+
System.out.println("Try 'cat --help' for more information.");
20+
return;
21+
}
22+
if (args.length > 2){
23+
System.out.println("Too many arguments. abord. ");
24+
System.out.println("Try 'cat --help' for more information.");
25+
return;
26+
}
27+
if (args[0].equals("--help") || args[0].equals("-h")){
28+
System.out.println("Usage: java SHAHash [TEXT] [DOMAIN]");
29+
System.out.println("Hash TEXT using SHA-512.\n");
30+
System.out.println("-h, --help display this help and exit.\n");
31+
return;
32+
}
33+
34+
String domain = (args.length == 1) ? DOMAIN : args[1];
35+
String hash = hashPassword(args[0], domain);
36+
37+
System.out.println("Hashed text: " + hash + " , len " + hash.length());
38+
}
39+
40+
/**
41+
* Hash a text using SHA-512
42+
* @param password text
43+
* @param domain domain or salt
44+
* @return thje hash
45+
*/
46+
public static String hashPassword(String password, String domain) {
47+
String pw = password + domain;
48+
MessageDigest sha;
49+
byte[] byteData;
50+
try {
51+
sha = MessageDigest.getInstance("SHA-512");
52+
byteData = sha.digest(pw.getBytes(StandardCharsets.UTF_8));
53+
return convertHex(byteData);
54+
} catch (NoSuchAlgorithmException e) {
55+
e.printStackTrace();
56+
return "";
57+
}
58+
}
59+
60+
/**
61+
* Convert byte array to String
62+
* @param byteData bytes
63+
* @return String
64+
*/
65+
private static String convertHex(byte[] byteData){
66+
StringBuilder hexString = new StringBuilder();
67+
for (byte byteDatum : byteData) {
68+
String hex = Integer.toHexString(0xff & byteDatum);
69+
if (hex.length() == 1) hexString.append('0');
70+
hexString.append(hex);
71+
}
72+
return hexString.toString();
73+
}
74+
75+
76+
}

doc/SHAHash.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
2+
3+
This document gathers the actions to set up the HASH generator for the modules "mi carro es tu carro".
4+
5+
# Frist time
6+
7+
To use the software you must have java installed on your machine.
8+
9+
## Installation
10+
11+
```bash
12+
~$ sudo dnf install java-11-openjdk
13+
```
14+
15+
## Execution
16+
17+
```bash
18+
~$ java SHAHash
19+
```
20+
21+
## Exemple of use
22+
23+
### Hash simple
24+
25+
```bash
26+
~$ java SHAHash "hes"
27+
Hashed text: 19dd4469b2fc7b78eca66ab48dcfb52654842866c6587d5e01a67845e41c53466ce5851ecd809c52b906976530a8637ed857dc301c8b24a221cbec0f8155a16c , len 128
28+
~$
29+
```
30+
31+
### Hash with domain
32+
33+
```bash
34+
~$ java SHAHash "hes" "f"
35+
Hashed text: 4d385ee3b33c37ba8e317f071d432a19ce53cdad9679c3059266888b96bb891503236acc65e09736f1f3cee6222b75b4dcd0b852b0312d0e8a83465324b78f27 , len 128
36+
~$
37+
```
38+
39+
### Exemple with MAC address
40+
41+
```bash
42+
~$ java SHAHash "4A:E5:FF:A7:25:9F"
43+
Hashed text: 588d80d54a9c0af7cc5f034e013d17732221a5d583bc5812e21b62d7299c98660080c9910bf62385d5e89d486a2622157db777078576f94f5a17d0098e1a4968, len 128
44+
~$
45+
```
46+
47+
48+
# Install from source
49+
50+
To run the program from the .java file, you must have the development version.
51+
52+
## Installation
53+
54+
```bash
55+
~$ sudo dnf install java-11-openjdk-devel
56+
```
57+
58+
## Execution
59+
60+
```bash
61+
~$ javac SHAHash.java
62+
63+
~$ java SHAHash
64+
Need an argument. abord.
65+
Try 'cat --help' for more information.
66+
```

doc/SHAHash.pdf

34.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)