Skip to content

Commit 3d9c23b

Browse files
committed
fix
1 parent 880e682 commit 3d9c23b

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

pom.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,18 @@
88
<artifactId>javaKit</artifactId>
99
<version>1.0-SNAPSHOT</version>
1010

11+
<dependencies>
12+
<dependency>
13+
<groupId>commons-codec</groupId>
14+
<artifactId>commons-codec</artifactId>
15+
<version>1.6</version>
16+
</dependency>
17+
</dependencies>
18+
1119
<properties>
1220
<maven.compiler.source>21</maven.compiler.source>
1321
<maven.compiler.target>21</maven.compiler.target>
1422
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1523
</properties>
16-
24+
1725
</project>

src/main/java/Base64.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,16 @@
1-
package PACKAGE_NAME;public class base64 {
1+
public class Base64 {
2+
public String encodeBase64(String input) {
3+
return java.util.Base64.getEncoder().encodeToString(input.getBytes());
4+
}
5+
6+
public String decodeBase64(String input) {
7+
return new String(java.util.Base64.getDecoder().decode(input));
8+
}
9+
10+
public static void main(String[] args) {
11+
Base64 base64 = new Base64();
12+
String encoded = base64.encodeBase64("password");
13+
System.out.println(encoded);
14+
System.out.println(base64.decodeBase64(encoded));
15+
}
216
}

src/main/java/MD5.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
1-
package PACKAGE_NAME;public class md5 {
1+
import org.apache.commons.codec.digest.DigestUtils;
2+
3+
import java.util.Random;
4+
5+
public class MD5 {
6+
public Hash generateMd5Hash(String input) {
7+
Hash hash = new Hash();
8+
hash.hash = DigestUtils.md5Hex(input);
9+
hash.isSalted = false;
10+
return hash;
11+
}
12+
13+
public Hash generateMd5HashPlusSalt(String input) {
14+
Hash hash = new Hash();
15+
hash.salt = new Random().nextInt(90000) + 10000 + "";
16+
hash.hash = DigestUtils.md5Hex(input + hash.salt);
17+
hash.isSalted = true;
18+
return hash;
19+
}
20+
21+
public boolean compareMd5Hash(String input, String inputSalt, String hash) {
22+
return DigestUtils.md5Hex(input + inputSalt).equals(hash);
23+
}
24+
25+
public boolean compareMd5Hash(String input, String hash) {
26+
return DigestUtils.md5Hex(input).equals(hash);
27+
}
28+
29+
public static void main(String[] args) {
30+
MD5 md5 = new MD5();
31+
Hash hash = md5.generateMd5Hash("password");
32+
System.out.println(hash.hash);
33+
System.out.println(hash.isSalted);
34+
Hash hashSalt = md5.generateMd5HashPlusSalt("password");
35+
System.out.println(hashSalt.hash);
36+
System.out.println(hashSalt.salt);
37+
System.out.println(hashSalt.isSalted);
38+
System.out.println(md5.compareMd5Hash("password", hash.hash));
39+
System.out.println(md5.compareMd5Hash("password", hashSalt.salt, hashSalt.hash));
40+
}
241
}

src/main/java/Random.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
public class Random {
2+
3+
}

0 commit comments

Comments
 (0)