Fix password encoding

This commit is contained in:
Matéo Duparc 2023-04-24 13:37:14 +02:00
parent 9d1bfd606f
commit e83cfc9794
Signed by: hardcoresushi
GPG Key ID: AFE384344A45E13A
2 changed files with 15 additions and 3 deletions

View File

@ -9,10 +9,11 @@ object WidgetUtil {
fun encodeEditTextContent(editText: EditText): ByteArray { fun encodeEditTextContent(editText: EditText): ByteArray {
val charArray = CharArray(editText.text.length) val charArray = CharArray(editText.text.length)
editText.text.getChars(0, editText.text.length, charArray, 0) editText.text.getChars(0, editText.text.length, charArray, 0)
val byteArray = StandardCharsets.UTF_8.encode( val byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(charArray))
CharBuffer.wrap(charArray)
).array()
Arrays.fill(charArray, Char.MIN_VALUE) Arrays.fill(charArray, Char.MIN_VALUE)
val byteArray = ByteArray(byteBuffer.remaining())
byteBuffer.get(byteArray)
Wiper.wipe(byteBuffer)
return byteArray return byteArray
} }
} }

View File

@ -8,10 +8,21 @@ import sushi.hardcore.droidfs.Constants
import sushi.hardcore.droidfs.R import sushi.hardcore.droidfs.R
import java.io.File import java.io.File
import java.io.FileOutputStream import java.io.FileOutputStream
import java.nio.ByteBuffer
import java.util.* import java.util.*
import kotlin.math.ceil import kotlin.math.ceil
object Wiper { 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 private const val buff_size = 4096
fun wipe(context: Context, uri: Uri): String? { fun wipe(context: Context, uri: Uri): String? {
val cursor = context.contentResolver.query(uri, null, null, null, null) val cursor = context.contentResolver.query(uri, null, null, null, null)