From e83cfc97940d9a1de14956d9fc24f52ca2fea3fe Mon Sep 17 00:00:00 2001 From: Hardcore Sushi Date: Mon, 24 Apr 2023 13:37:14 +0200 Subject: [PATCH] Fix password encoding --- .../java/sushi/hardcore/droidfs/util/WidgetUtil.kt | 7 ++++--- .../main/java/sushi/hardcore/droidfs/util/Wiper.kt | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/sushi/hardcore/droidfs/util/WidgetUtil.kt b/app/src/main/java/sushi/hardcore/droidfs/util/WidgetUtil.kt index 910ff58..8003c72 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/util/WidgetUtil.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/util/WidgetUtil.kt @@ -9,10 +9,11 @@ object WidgetUtil { fun encodeEditTextContent(editText: EditText): ByteArray { val charArray = CharArray(editText.text.length) editText.text.getChars(0, editText.text.length, charArray, 0) - val byteArray = StandardCharsets.UTF_8.encode( - CharBuffer.wrap(charArray) - ).array() + val byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(charArray)) Arrays.fill(charArray, Char.MIN_VALUE) + val byteArray = ByteArray(byteBuffer.remaining()) + byteBuffer.get(byteArray) + Wiper.wipe(byteBuffer) return byteArray } } \ No newline at end of file diff --git a/app/src/main/java/sushi/hardcore/droidfs/util/Wiper.kt b/app/src/main/java/sushi/hardcore/droidfs/util/Wiper.kt index a6f36ba..c813c6c 100644 --- a/app/src/main/java/sushi/hardcore/droidfs/util/Wiper.kt +++ b/app/src/main/java/sushi/hardcore/droidfs/util/Wiper.kt @@ -8,10 +8,21 @@ import sushi.hardcore.droidfs.Constants import sushi.hardcore.droidfs.R import java.io.File import java.io.FileOutputStream +import java.nio.ByteBuffer import java.util.* import kotlin.math.ceil object Wiper { + fun wipe(byteBuffer: ByteBuffer) { + if (byteBuffer.hasArray()) { + Arrays.fill(byteBuffer.array(), Byte.MIN_VALUE) + } else { + for (i in 0 until byteBuffer.limit()) { + byteBuffer.put(i, Byte.MIN_VALUE) + } + } + } + private const val buff_size = 4096 fun wipe(context: Context, uri: Uri): String? { val cursor = context.contentResolver.query(uri, null, null, null, null)