-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
55883e0
commit f57f4e7
Showing
11 changed files
with
149 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/pl/nightdev701/crypto/generator/AESKeyGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package pl.nightdev701.crypto.generator; | ||
|
||
import pl.nightdev701.logger.AbstractLogger; | ||
import pl.nightdev701.util.key.CryptKeyGenerator; | ||
|
||
import javax.crypto.KeyGenerator; | ||
import javax.crypto.SecretKey; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.logging.Level; | ||
|
||
public class AESKeyGenerator implements CryptKeyGenerator { | ||
|
||
AbstractLogger logger; | ||
|
||
public AESKeyGenerator(AbstractLogger logger) { | ||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
public String generateKey() { | ||
try { | ||
KeyGenerator keyGenerator = KeyGenerator.getInstance("AES"); | ||
|
||
keyGenerator.init(128); | ||
|
||
SecretKey secretKey = keyGenerator.generateKey(); | ||
|
||
byte[] keyBytes = secretKey.getEncoded(); | ||
|
||
logger.log(Level.INFO, "Key generated for algorithms: AES"); | ||
|
||
return java.util.Base64.getEncoder().encodeToString(keyBytes); | ||
|
||
} catch (NoSuchAlgorithmException e) { | ||
e.printStackTrace(); | ||
logger.log(Level.INFO, "Key failed to generate for algorithms: AES"); | ||
} | ||
return null; | ||
} | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/pl/nightdev701/crypto/generator/BlowFishGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package pl.nightdev701.crypto.generator; | ||
|
||
import pl.nightdev701.logger.AbstractLogger; | ||
import pl.nightdev701.util.key.CryptKeyGenerator; | ||
|
||
import javax.crypto.KeyGenerator; | ||
import javax.crypto.SecretKey; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.logging.Level; | ||
|
||
public class BlowFishGenerator implements CryptKeyGenerator { | ||
|
||
private AbstractLogger logger; | ||
|
||
public BlowFishGenerator(AbstractLogger logger) { | ||
this.logger = logger; | ||
} | ||
|
||
@Override | ||
public String generateKey() { | ||
try { | ||
KeyGenerator keyGenerator = KeyGenerator.getInstance("Blowfish"); | ||
|
||
keyGenerator.init(128); | ||
|
||
SecretKey secretKey = keyGenerator.generateKey(); | ||
|
||
byte[] keyBytes = secretKey.getEncoded(); | ||
|
||
logger.log(Level.INFO, "Key generated for algorithms: Blowfish"); | ||
|
||
return java.util.Base64.getEncoder().encodeToString(keyBytes); | ||
|
||
} catch (NoSuchAlgorithmException e) { | ||
e.printStackTrace(); | ||
logger.log(Level.INFO, "Key failed to generate for algorithms: AES"); | ||
} | ||
return null; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/main/java/pl/nightdev701/manager/KeyGeneratorManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package pl.nightdev701.manager; | ||
|
||
import pl.nightdev701.crypto.generator.AESKeyGenerator; | ||
import pl.nightdev701.crypto.generator.BlowFishGenerator; | ||
import pl.nightdev701.logger.AbstractLogger; | ||
import pl.nightdev701.util.CryptType; | ||
import pl.nightdev701.util.key.CryptKeyGenerator; | ||
|
||
public class KeyGeneratorManager { | ||
|
||
private CryptKeyGenerator generator; | ||
|
||
public KeyGeneratorManager(CryptType type, AbstractLogger logger) { | ||
|
||
if (type == CryptType.AES) { | ||
this.generator = new AESKeyGenerator(logger); | ||
} | ||
if (type == CryptType.BLOWFISH) { | ||
this.generator = new BlowFishGenerator(logger); | ||
} | ||
} | ||
|
||
public String generateKey() { | ||
return generator.generateKey(); | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...pl/nightdev701/util/crypto/CryptType.java → ...n/java/pl/nightdev701/util/CryptType.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package pl.nightdev701.util.crypto; | ||
package pl.nightdev701.util; | ||
|
||
public enum CryptType { | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package pl.nightdev701.util.key; | ||
|
||
public interface CryptKeyGenerator { | ||
|
||
String generateKey(); | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...ava/pl/nightdev701/util/StringHelper.java → ...nightdev701/util/string/StringHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package pl.nightdev701.util; | ||
package pl.nightdev701.util.string; | ||
|
||
public class StringHelper { | ||
|
||
|