diff --git a/src/main/java/de/tudbut/tools/encryption/RawKey.java b/src/main/java/de/tudbut/tools/encryption/RawKey.java index 5fab806..68678bd 100644 --- a/src/main/java/de/tudbut/tools/encryption/RawKey.java +++ b/src/main/java/de/tudbut/tools/encryption/RawKey.java @@ -45,7 +45,20 @@ public class RawKey extends Key { * @return encrypted string */ public String encryptString(String s) { - byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1); + return new String(encryptBytes(string.getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1); + } + + /** + * Decrypts a string + * @param s string to decrypt + * @return decrypted string + */ + public String decryptString(String s) { + return new String(decryptBytes(string.getBytes(StandardCharsets.ISO_8859_1)), StandardCharsets.ISO_8859_1); + } + + public byte[] encryptBytes(byte[] bytes) { + bytes = bytes.clone(); byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1); int len = bytes.length; int p = eb.length; @@ -55,16 +68,11 @@ public class RawKey extends Key { bytes[idx] = (byte) ((int) bytes[idx] + (int) eb[j]); } } - return new String(bytes, StandardCharsets.ISO_8859_1); + return bytes; } - - /** - * Decrypts a string - * @param s string to decrypt - * @return decrypted string - */ - public String decryptString(String s) { - byte[] bytes = s.getBytes(StandardCharsets.ISO_8859_1); + + public byte[] decryptBytes(byte[] bytes) { + bytes = bytes.clone(); byte[] eb = string.getBytes(StandardCharsets.ISO_8859_1); int len = bytes.length; int p = eb.length; @@ -74,7 +82,7 @@ public class RawKey extends Key { bytes[idx] = (byte) ((int) bytes[idx] - (int) eb[j]); } } - return new String(bytes, StandardCharsets.ISO_8859_1); + return bytes; } @Override