Fixed that Byte is signed but Char is unsigned

This commit is contained in:
dankito 2020-10-17 22:56:50 +02:00
parent fcde0dcf5b
commit a72e7d744c
1 changed files with 11 additions and 1 deletions

View File

@ -130,7 +130,17 @@ open class CryptographyManager {
} }
protected open fun mapToChars(plainTextBytes: ByteArray): CharArray { 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()
}
} }