From a72e7d744cf5654ec0d9ee676fa5186edbd7843d Mon Sep 17 00:00:00 2001 From: dankito Date: Sat, 17 Oct 2020 22:56:50 +0200 Subject: [PATCH] Fixed that Byte is signed but Char is unsigned --- .../ui/android/security/CryptographyManager.kt | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/security/CryptographyManager.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/security/CryptographyManager.kt index 5822839a..b99f5f55 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/security/CryptographyManager.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/security/CryptographyManager.kt @@ -130,7 +130,17 @@ open class CryptographyManager { } protected open fun mapToChars(plainTextBytes: ByteArray): CharArray { - return plainTextBytes.map { it.toChar() }.toCharArray() + return plainTextBytes.map { mapToChar(it) }.toCharArray() + } + + protected open fun mapToChar(byte: Byte): Char { + // Byte is signed but Char isn't -> convert negative byte values to positive ones + if (byte.toInt() < 0) { + return (256 + byte.toInt()).toChar() + } + else { + return byte.toChar() + } }