The error you’re encountering is a javax.crypto.IllegalBlockSizeException, specifically caused by error:1e00007b:Cipher functions:OPENSSL_internal:WRONG_FINAL_BLOCK_LENGTH. This typically occurs when there’s an issue with the encryption or decryption process, such as an incorrect block size or padding.
In your case, it seems to be happening within the decrypt function in your code, particularly at line 32 in the en_decrypt.kt file. The exception is thrown when attempting to finalize the decryption process.
object constants{
val secretKey = "We1c0me159@Ayush_Devdaas"
}
@OptIn(ExperimentalEncodingApi::class)
fun encrypt(password: String, secretKey: String): String {
val cipher = Cipher.getInstance("AES/ECB/PKCS5Padding")
val key = SecretKeySpec(secretKey.toByteArray(), "AES")
cipher.init(Cipher.ENCRYPT_MODE, key)
val encryptedBytes = cipher.doFinal(password.toByteArray())
return Base64.encode(encryptedBytes)
}
fun convertToStars(encryptedPass: String): String {
val length = encryptedPass.length
return "*".repeat(length)
}
@OptIn(ExperimentalEncodingApi::class)
fun decrypt(encryptedPass: String, secretKey: String): String{
val cipher = Cipher.getInstance("AES/ECB/PKCS5Padding")
val key = SecretKeySpec(secretKey.toByteArray(), "AES")
cipher.init(Cipher.DECRYPT_MODE, key)
val decryptedBytes = cipher.doFinal(Base64.decode(encryptedPass))
return String(decryptedBytes)
}