By default, the latitude and longitude of the GPS data collected by m-Path Sense are encrypted
using an asymmetric curve25519 key to provide extra protection for these highly sensitive data.
This function takes a character vector and decrypts its longitude and latitude columns using the
provided key.
Arguments
- data
A character vector containing hexadecimal (i.e. encrypted) data.
- key
A curve25519 private key.
- ignore
A string with characters to ignore from
data. Seesodium::hex2bin().
Parallel
This function supports parallel processing in the sense that it is able to
distribute it's computation load among multiple workers. To make use of this functionality, run
future::plan("multisession") before
calling this function.
Examples
library(dplyr)
library(sodium)
# Create some GPS coordinates.
data <- data.frame(
participant_id = "12345",
time = as.POSIXct(c(
"2022-12-02 12:00:00",
"2022-12-02 12:00:01",
"2022-12-02 12:00:02"
)),
longitude = c("50.12345", "50.23456", "50.34567"),
latitude = c("4.12345", "4.23456", "4.345678")
)
# Generate keypair
key <- sodium::keygen()
pub <- sodium::pubkey(key)
# Encrypt coordinates with pubkey
# You do not need to do this for m-Path Sense
# as this is already encrypted
encrypt <- function(data, pub) {
data <- lapply(data, charToRaw)
data <- lapply(data, function(x) sodium::simple_encrypt(x, pub))
data <- lapply(data, sodium::bin2hex)
data <- unlist(data)
data
}
data$longitude <- encrypt(data$longitude, pub)
data$latitude <- encrypt(data$latitude, pub)
# Once the data has been collected, decrypt it using decrypt_gps().
data |>
mutate(longitude = decrypt_gps(longitude, key)) |>
mutate(latitude = decrypt_gps(latitude, key))
#> participant_id time longitude latitude
#> 1 12345 2022-12-02 12:00:00 50.12345 4.123450
#> 2 12345 2022-12-02 12:00:01 50.23456 4.234560
#> 3 12345 2022-12-02 12:00:02 50.34567 4.345678
