1 | package com.jsql.util.bruter; | |
2 | ||
3 | import com.jsql.util.StringUtil; | |
4 | ||
5 | import java.nio.charset.StandardCharsets; | |
6 | import java.security.MessageDigest; | |
7 | import java.security.NoSuchAlgorithmException; | |
8 | import java.util.zip.CRC32; | |
9 | import java.util.zip.Checksum; | |
10 | ||
11 | public class HashUtil { | |
12 | | |
13 | private HashUtil() { | |
14 | // Nothing | |
15 | } | |
16 | | |
17 | public static String toAdler32(String text) { | |
18 | byte[] bytes = text.getBytes(StandardCharsets.UTF_8); | |
19 | Checksum checksum = new java.util.zip.Adler32(); | |
20 |
1
1. toAdler32 : removed call to java/util/zip/Checksum::update → KILLED |
checksum.update(bytes,0,bytes.length); |
21 | | |
22 |
1
1. toAdler32 : replaced return value with "" for com/jsql/util/bruter/HashUtil::toAdler32 → KILLED |
return String.valueOf(checksum.getValue()); |
23 | } | |
24 | | |
25 | public static String toCrc16(String text) { | |
26 |
1
1. toCrc16 : replaced return value with "" for com/jsql/util/bruter/HashUtil::toCrc16 → KILLED |
return Crc16Helper.generateCRC16(text); |
27 | } | |
28 | | |
29 | public static String toCrc64(String text) { | |
30 |
1
1. toCrc64 : replaced return value with "" for com/jsql/util/bruter/HashUtil::toCrc64 → KILLED |
return Crc64Helper.generateCRC64(text.getBytes(StandardCharsets.UTF_8)); |
31 | } | |
32 | | |
33 | public static String toMySql(String textInput) throws NoSuchAlgorithmException { | |
34 | var messageDigest = MessageDigest.getInstance(Coder.SHA1.label); | |
35 | | |
36 | var password = String.valueOf(textInput.toCharArray()); | |
37 | | |
38 | byte[] passwordBytes = password.getBytes(StandardCharsets.UTF_8); | |
39 |
1
1. toMySql : removed call to java/security/MessageDigest::update → SURVIVED |
messageDigest.update(passwordBytes, 0, passwordBytes.length); |
40 | | |
41 | byte[] hashSHA1 = messageDigest.digest(); | |
42 | var stringSHA1 = HashUtil.digestToHexString(hashSHA1); | |
43 | | |
44 | var passwordSHA1 = String.valueOf(StringUtil.hexstr(stringSHA1).toCharArray()); | |
45 | byte[] passwordSHA1Bytes = passwordSHA1.getBytes(StandardCharsets.UTF_8); | |
46 | | |
47 |
1
1. toMySql : removed call to java/security/MessageDigest::update → SURVIVED |
messageDigest.update(passwordSHA1Bytes, 0, passwordSHA1Bytes.length); |
48 | byte[] hashSHA1SH1 = messageDigest.digest(); | |
49 |
1
1. toMySql : replaced return value with "" for com/jsql/util/bruter/HashUtil::toMySql → KILLED |
return HashUtil.digestToHexString(hashSHA1SH1); |
50 | } | |
51 | ||
52 | public static String toCrc32(String textInput) { | |
53 | byte[] bytes = textInput.getBytes(StandardCharsets.UTF_8); | |
54 | | |
55 | Checksum checksum = new CRC32(); | |
56 |
1
1. toCrc32 : removed call to java/util/zip/Checksum::update → KILLED |
checksum.update(bytes, 0, bytes.length); |
57 | | |
58 | long lngChecksum = checksum.getValue(); | |
59 |
1
1. toCrc32 : replaced return value with "" for com/jsql/util/bruter/HashUtil::toCrc32 → KILLED |
return Long.toString(lngChecksum); |
60 | } | |
61 | ||
62 | public static String toMd4(String textInput) { | |
63 | MessageDigest messageDigest = new DigestMD4(); | |
64 | ||
65 | var passwordString = String.valueOf(textInput.toCharArray()); | |
66 | byte[] passwordByte = passwordString.getBytes(StandardCharsets.UTF_8); | |
67 | | |
68 |
1
1. toMd4 : removed call to java/security/MessageDigest::update → KILLED |
messageDigest.update(passwordByte, 0, passwordByte.length); |
69 | byte[] encodedPassword = messageDigest.digest(); | |
70 |
1
1. toMd4 : replaced return value with "" for com/jsql/util/bruter/HashUtil::toMd4 → KILLED |
return HashUtil.digestToHexString(encodedPassword); |
71 | } | |
72 | ||
73 | public static String toHash(String nameMethod, String textInput) throws NoSuchAlgorithmException { | |
74 | var messageDigest = MessageDigest.getInstance(nameMethod); | |
75 | | |
76 | var passwordString = String.valueOf(textInput.toCharArray()); | |
77 | byte[] passwordByte = passwordString.getBytes(StandardCharsets.UTF_8); | |
78 | | |
79 |
1
1. toHash : removed call to java/security/MessageDigest::update → TIMED_OUT |
messageDigest.update(passwordByte, 0, passwordByte.length); |
80 | byte[] encodedPassword = messageDigest.digest(); | |
81 |
1
1. toHash : replaced return value with "" for com/jsql/util/bruter/HashUtil::toHash → TIMED_OUT |
return HashUtil.digestToHexString(encodedPassword); |
82 | } | |
83 | | |
84 | /** | |
85 | * Convert a digest hash to a string representation. | |
86 | * @param block Digest array | |
87 | * @return Hash as a string | |
88 | */ | |
89 | public static String digestToHexString(byte[] block) { | |
90 | var buf = new StringBuilder(); | |
91 | for (byte b : block) { | |
92 |
1
1. digestToHexString : removed call to com/jsql/util/bruter/HashUtil::byte2hex → TIMED_OUT |
HashUtil.byte2hex(b, buf); |
93 | } | |
94 |
1
1. digestToHexString : replaced return value with "" for com/jsql/util/bruter/HashUtil::digestToHexString → TIMED_OUT |
return buf.toString(); |
95 | } | |
96 | | |
97 | /** | |
98 | * Convert byte character to hexadecimal StringBuffer character. | |
99 | * @param b Byte character to convert | |
100 | * @param buf Hexadecimal converted character | |
101 | */ | |
102 | private static void byte2hex(byte b, StringBuilder buf) { | |
103 | var hexChars = new char[]{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' }; | |
104 |
2
1. byte2hex : Replaced Shift Right with Shift Left → KILLED 2. byte2hex : Replaced bitwise AND with OR → KILLED |
int high = (b & 0xf0) >> 4; |
105 |
1
1. byte2hex : Replaced bitwise AND with OR → KILLED |
int low = b & 0x0f; |
106 | buf.append(hexChars[high]); | |
107 | buf.append(hexChars[low]); | |
108 | } | |
109 | } | |
Mutations | ||
20 |
1.1 |
|
22 |
1.1 |
|
26 |
1.1 |
|
30 |
1.1 |
|
39 |
1.1 |
|
47 |
1.1 |
|
49 |
1.1 |
|
56 |
1.1 |
|
59 |
1.1 |
|
68 |
1.1 |
|
70 |
1.1 |
|
79 |
1.1 |
|
81 |
1.1 |
|
92 |
1.1 |
|
94 |
1.1 |
|
104 |
1.1 2.2 |
|
105 |
1.1 |