From cb428937d47ef3873ac4171ba12470332c6818b5 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 2 Oct 2018 15:36:56 +0200 Subject: [PATCH] Fix decode feature in the app (MUST BE CHECKED) --- .../java/com/herbron/moodl/DataManagers/DataCrypter.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/com/herbron/moodl/DataManagers/DataCrypter.java b/app/src/main/java/com/herbron/moodl/DataManagers/DataCrypter.java index 2abe2ce..006cd81 100644 --- a/app/src/main/java/com/herbron/moodl/DataManagers/DataCrypter.java +++ b/app/src/main/java/com/herbron/moodl/DataManagers/DataCrypter.java @@ -73,10 +73,12 @@ public class DataCrypter { IvParameterSpec ivParameterSpec = new IvParameterSpec(context.getString(R.string.ivKey).getBytes("UTF-8")); Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5PADDING"); - cipher.init(Cipher.ENCRYPT_MODE, aesKey, ivParameterSpec); + cipher.init(Cipher.DECRYPT_MODE, aesKey, ivParameterSpec); + + byte[] decryptedBytes = cipher.doFinal(data.getBytes("UTF-8")); - byte[] dataBytes = Base64.decode(data, Base64.DEFAULT); - decryptedData = new String(dataBytes, StandardCharsets.UTF_8); + //byte[] dataBytes = Base64.decode(data, Base64.DEFAULT); + decryptedData = new String(decryptedBytes, StandardCharsets.UTF_8); } catch(NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | UnsupportedEncodingException