Fixed that Byte is signed but Char is unsigned
This commit is contained in:
parent
fcde0dcf5b
commit
a72e7d744c
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue