Skip to content

Commit

Permalink
OpenAPI 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NightDev701 committed Dec 15, 2023
1 parent 55883e0 commit f57f4e7
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 22 deletions.
26 changes: 23 additions & 3 deletions src/main/java/pl/nightdev701/OpenAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
import pl.nightdev701.logger.AbstractLogger;
import pl.nightdev701.logger.standard.DefaultLogger;
import pl.nightdev701.manager.CryptManager;
import pl.nightdev701.manager.KeyGeneratorManager;
import pl.nightdev701.network.http.HttpRequestHandler;
import pl.nightdev701.network.tcp.ProxyAdapter;
import pl.nightdev701.util.crypto.CryptType;
import pl.nightdev701.util.CryptType;
import pl.nightdev701.util.stream.OpenPrintStream;

import java.io.FileNotFoundException;
Expand All @@ -34,6 +35,25 @@

public class OpenAPI {

/**
* generate keys
*
* @param type
*/
public static KeyGeneratorManager getKeyGeneratorManager(CryptType type) {
return getKeyGeneratorManager(type, new DefaultLogger());
}

/**
* generate keys
*
* @param type
* @param logger
*/
public static KeyGeneratorManager getKeyGeneratorManager(CryptType type, AbstractLogger logger) {
return new KeyGeneratorManager(type, logger);
}

/**
* encrypt and decrypt strings
*
Expand Down Expand Up @@ -65,11 +85,11 @@ public static DatabaseConnector getDatabaseManager(DatabaseFormular formular, Da
return getDatabaseManager(formular, type, port, new DefaultLogger());
}

public static ScorpionFileReader getFileReader(String path, AbstractLogger logger){
public static ScorpionFileReader getFileReader(String path, AbstractLogger logger) {
return new ScorpionFileReader(path, logger);
}

public static ScorpionFileReader getFileReader(String path){
public static ScorpionFileReader getFileReader(String path) {
return getFileReader(path, new DefaultLogger());
}

Expand Down
5 changes: 0 additions & 5 deletions src/main/java/pl/nightdev701/crypto/BlowFishCrypto.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package pl.nightdev701.crypto;

import pl.nightdev701.logger.AbstractLogger;
import pl.nightdev701.logger.standard.DefaultLogger;
import pl.nightdev701.util.crypto.CryptoForm;

import javax.crypto.Cipher;
Expand All @@ -16,10 +15,6 @@ public class BlowFishCrypto implements CryptoForm {
private final String encryptionKey;
private final AbstractLogger logger;

public BlowFishCrypto(String encryptionKey) {
this(encryptionKey, new DefaultLogger());
}

public BlowFishCrypto(String encryptionKey, AbstractLogger logger) {
this.encryptionKey = encryptionKey;
this.logger = logger;
Expand Down
5 changes: 0 additions & 5 deletions src/main/java/pl/nightdev701/crypto/CryptoAes.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
*/

import pl.nightdev701.logger.AbstractLogger;
import pl.nightdev701.logger.standard.DefaultLogger;
import pl.nightdev701.util.crypto.CryptoForm;

import javax.crypto.Cipher;
Expand All @@ -25,10 +24,6 @@ public class CryptoAes implements CryptoForm {
private final String encryptionKey;
private final AbstractLogger logger;

public CryptoAes(String encryptionKey) {
this(encryptionKey, new DefaultLogger());
}

public CryptoAes(String encryptionKey, AbstractLogger logger) {
this.encryptionKey = encryptionKey;
this.logger = logger;
Expand Down
41 changes: 41 additions & 0 deletions src/main/java/pl/nightdev701/crypto/generator/AESKeyGenerator.java
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;
}

}
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;
}

}
8 changes: 4 additions & 4 deletions src/main/java/pl/nightdev701/io/ScorpionFileReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public ScorpionFileReader(String filePath, AbstractLogger logger) {
bufferedReader = new BufferedReader(fileReader);
currentLine = bufferedReader.readLine(); // Lese die erste Zeile
} catch (FileNotFoundException e) {
logger.log(Level.WARNING,"Die Datei wurde nicht gefunden: " + e.getMessage());
logger.log(Level.WARNING, "Die Datei wurde nicht gefunden: " + e.getMessage());
} catch (IOException e) {
logger.log(Level.WARNING,"Fehler beim Lesen der Datei: " + e.getMessage());
logger.log(Level.WARNING, "Fehler beim Lesen der Datei: " + e.getMessage());
}
}

Expand All @@ -37,7 +37,7 @@ public void readNextLine() {
try {
currentLine = bufferedReader.readLine(); // Gehe zur nächsten Zeile
} catch (IOException e) {
logger.log(Level.WARNING,"Fehler beim Lesen der nächsten Zeile: " + e.getMessage());
logger.log(Level.WARNING, "Fehler beim Lesen der nächsten Zeile: " + e.getMessage());
}
}

Expand All @@ -47,7 +47,7 @@ public void close() {
bufferedReader.close();
}
} catch (IOException e) {
logger.log(Level.WARNING,"Fehler beim Schließen des Readers: " + e.getMessage());
logger.log(Level.WARNING, "Fehler beim Schließen des Readers: " + e.getMessage());
}
}

Expand Down
7 changes: 4 additions & 3 deletions src/main/java/pl/nightdev701/manager/CryptManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import pl.nightdev701.crypto.BlowFishCrypto;
import pl.nightdev701.crypto.CryptoAes;
import pl.nightdev701.logger.AbstractLogger;
import pl.nightdev701.util.crypto.CryptType;
import pl.nightdev701.util.CryptType;
import pl.nightdev701.util.crypto.CryptoForm;

public class CryptManager {
Expand All @@ -12,10 +12,10 @@ public class CryptManager {

public CryptManager(String key, CryptType type, AbstractLogger logger) {
if (type == CryptType.AES) {
this.crypt = new CryptoAes(key);
this.crypt = new CryptoAes(key, logger);
}
if (type == CryptType.BLOWFISH) {
this.crypt = new BlowFishCrypto(key);
this.crypt = new BlowFishCrypto(key, logger);
}
}

Expand All @@ -38,4 +38,5 @@ public String decrypt(String text) {
public CryptoForm getCrypt() {
return crypt;
}

}
27 changes: 27 additions & 0 deletions src/main/java/pl/nightdev701/manager/KeyGeneratorManager.java
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();
}

}
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 {

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/pl/nightdev701/util/key/CryptKeyGenerator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package pl.nightdev701.util.key;

public interface CryptKeyGenerator {

String generateKey();

}
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 {

Expand Down

0 comments on commit f57f4e7

Please sign in to comment.