Skip to content
This repository was archived by the owner on Mar 3, 2020. It is now read-only.
This repository was archived by the owner on Mar 3, 2020. It is now read-only.

String.getBytes("UTF-16") returns different value on Mac #138

@yshrsmz

Description

@yshrsmz

TL; DR

Implementation of Entity#getBytes is currently mName.getBytes("UTF-16"), but it should be either mName.getBytes("UTF-16BE") or mName.getBytes("UTF-16LE")

detail

I am trying to implement java cli app to decrypt files encrypted by conceal, and getting tag mismatch error all the time.
And after some investigation I realized that the result of String.getBytes("UTF-16") is different between Android and Mac.

when I execute Arrays.toString("teststring".getBytes("UTF-16")) on Android, it returns

[-1, -2, 116, 0, 101, 0, 115, 0, 116, 0, 115, 0, 116, 0, 114, 0, 105, 0, 110, 0, 103, 0]

but when I execute same code on mac as gradle task or standard java project, it returns

[-2, -1, 0, 116, 0, 101, 0, 115, 0, 116, 0, 115, 0, 116, 0, 114, 0, 105, 0, 110, 0, 103]

Apparently this is why I got tag mismatch error all the time :(

To fix this issue, I create custom Entity class whose getBytes method encodes mName with UTF-16LE.

But I think this should be done in library side. any thought?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions