From 0077cebaa637ccdf1d63916065c508ef761d0f52 Mon Sep 17 00:00:00 2001 From: Sofie <117321707+Sofie99@users.noreply.github.com> Date: Sat, 18 Nov 2023 21:30:56 +0700 Subject: [PATCH] fixed AesHelper (#773) Co-authored-by: Sofie99 --- .../cloudstream3/extractors/helper/AesHelper.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/extractors/helper/AesHelper.kt b/app/src/main/java/com/lagradost/cloudstream3/extractors/helper/AesHelper.kt index b41eae52..9c5ceb8c 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/extractors/helper/AesHelper.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/extractors/helper/AesHelper.kt @@ -1,7 +1,6 @@ package com.lagradost.cloudstream3.extractors.helper import com.fasterxml.jackson.annotation.JsonProperty -import com.lagradost.cloudstream3.ErrorLoadingException import com.lagradost.cloudstream3.base64DecodeArray import com.lagradost.cloudstream3.base64Encode import com.lagradost.cloudstream3.utils.AppUtils @@ -23,7 +22,12 @@ object AesHelper { padding: String = HASH, ): String? { val parse = AppUtils.tryParseJson(data) ?: return null - val (key, iv) = generateKeyAndIv(pass, parse.s.hexToByteArray()) ?: return null + val (key, iv) = generateKeyAndIv( + pass, + parse.s.hexToByteArray(), + ivLength = parse.iv.length / 2, + saltLength = parse.s.length / 2 + ) ?: return null val cipher = Cipher.getInstance(padding) return if (!encrypt) { cipher.init(Cipher.DECRYPT_MODE, SecretKeySpec(key, "AES"), IvParameterSpec(iv)) @@ -40,7 +44,8 @@ object AesHelper { salt: ByteArray, hashAlgorithm: String = KDF, keyLength: Int = 32, - ivLength: Int = 16, + ivLength: Int, + saltLength: Int, iterations: Int = 1 ): Pair? { @@ -63,7 +68,7 @@ object AesHelper { ) md.update(password) - md.update(salt, 0, 8) + md.update(salt, 0, saltLength) md.digest(generatedData, generatedLength, digestLength) for (i in 1 until iterations) {