summaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorAizistral2022-10-08 22:56:15 +0200
committerAizistral2022-10-08 22:56:15 +0200
commit11a3bda02e99609c2fa5da2b0541fedbdd947ea9 (patch)
tree0707f88788e90362650051b280c9cd4818dedccc /src/main
parent992a3b6ea7b144f887d72000757cef236f8045c6 (diff)
Fix Base64 messages being recognized as commands
Fixes #223
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/com/aizistral/nochatreports/encryption/AESEncryptor.java8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/main/java/com/aizistral/nochatreports/encryption/AESEncryptor.java b/src/main/java/com/aizistral/nochatreports/encryption/AESEncryptor.java
index b7b8335..f09cd02 100644
--- a/src/main/java/com/aizistral/nochatreports/encryption/AESEncryptor.java
+++ b/src/main/java/com/aizistral/nochatreports/encryption/AESEncryptor.java
@@ -77,9 +77,9 @@ public abstract class AESEncryptor<T extends AESEncryption> extends Encryptor<T>
this.encryptor.init(ENCRYPT_MODE, this.key, tuple.getA());
byte[] encrypted = this.encryptor.doFinal(message.getBytes());
- return BASE64_ENCODER.encodeToString(ByteBuffer.allocate(encrypted.length + tuple.getB().length).put(tuple.getB()).put(encrypted).array());
+ return BASE64_ENCODER.encodeToString(ByteBuffer.allocate(encrypted.length + tuple.getB().length).put(tuple.getB()).put(encrypted).array()).replace('/', '\\');
} else
- return BASE64_ENCODER.encodeToString(this.encryptor.doFinal(message.getBytes()));
+ return BASE64_ENCODER.encodeToString(this.encryptor.doFinal(message.getBytes())).replace('/', '\\');
} catch (IllegalBlockSizeException | BadPaddingException | InvalidKeyException | InvalidAlgorithmParameterException ex) {
throw new RuntimeException(ex);
}
@@ -89,12 +89,12 @@ public abstract class AESEncryptor<T extends AESEncryption> extends Encryptor<T>
public String decrypt(String message) {
try {
if (this.useIV) {
- var tuple = this.splitIV(BASE64_DECODER.decode(message));
+ var tuple = this.splitIV(BASE64_DECODER.decode(message.replace('\\', '/')));
this.decryptor.init(DECRYPT_MODE, this.key, tuple.getA());
return new String(this.decryptor.doFinal(tuple.getB()), StandardCharsets.UTF_8);
} else
- return new String(this.decryptor.doFinal(BASE64_DECODER.decode(message)), StandardCharsets.UTF_8);
+ return new String(this.decryptor.doFinal(BASE64_DECODER.decode(message.replace('\\', '/'))), StandardCharsets.UTF_8);
} catch (AEADBadTagException ex) {
return "???";
} catch (IllegalBlockSizeException | BadPaddingException | InvalidKeyException | InvalidAlgorithmParameterException ex) {