From 11a3bda02e99609c2fa5da2b0541fedbdd947ea9 Mon Sep 17 00:00:00 2001 From: Aizistral Date: Sat, 8 Oct 2022 22:56:15 +0200 Subject: Fix Base64 messages being recognized as commands Fixes #223 --- .../java/com/aizistral/nochatreports/encryption/AESEncryptor.java | 8 ++++---- 1 file 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 extends Encryptor 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 extends Encryptor 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) { -- cgit v1.2.3