0

I am using the digest function to mask some sensitive information in R. Is it possible to retrieve the original data after masking?

Any insights would be highly appreciated.

Thanks Priyanka

  • 1
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input. We have no idea what your code does so it's hard to say for sure what's going on. – MrFlick Jun 18 '18 at 16:24
  • anonymize <- function(x, algo="crc32"){ unq_hashes <- vapply(unique(x), function(object) digest(object, algo=algo), FUN.VALUE="", USE.NAMES=TRUE) unname(unq_hashes[x]) } # choose columns to mask cols_to_mask <-c("BENE_NUM","BENE_EQTB_NUM") # backup original data data_copy<-copy(my_data) # anonymize my_data[,(cols_to_mask):= lapply(.SD, anonymize),.SDcols=cols_to_mask,with=FALSE] – priyanka singh Jun 18 '18 at 20:03

1 Answers1

1

No it's not possible. If you just need to hide the data from plain sight, you can use base 64 encoding. E.g.:

library(base64enc)

x <- "sensitive data"
x64 <- base64enc::base64encode(charToRaw(x))
print(x64)
[1] "c2Vuc2l0aXZlIGRhdGE="

rawToChar(base64decode(x64))

[1] "sensitive data"

Otherwise, you can use encryption, which there are packages for.

thc
  • 9,527
  • 1
  • 24
  • 39