Skip to content

Handling UTF-8 encoding on Windows #10

Description

@martroben

When I encrypt and decrypt data that has UTF-8 encoding on a Windows device, I get messed up results:

"õ" %>%
enc2utf8() %>%
encrypt_vec(public_key_path = paste0(key_file_name, ".pub")) %>%
decrypt_vec(private_key_path = key_file_name)

[1] "Ƶ"

It seems to happen because rawToChar() function uses whatever the default locale/encoding for the current Windows OS is.

"õ" %>%
enc2utf8() %>%
charToRaw() %>%
rawToChar()

[1] "Ƶ"

The problem could be fixed by adding an extra step to convert decrypted strings to UTF-8

"õ" %>%
enc2utf8() %>%
charToRaw() %>%
rawToChar() %>%
stringi::stri_conv("UTF-8")

[1] "õ"

Love your package, cheers!

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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