15.8 Using a lookup table
Rather than storing the ciphertext in the working data frame, a lookup table can be used as an alternative.
lookup = TRUE has the following effects:
- returns the data frame / tibble with encrypted columns removed and a
- returns the lookup table as an object in the R environment;
- creates a lookup table
.csvfile in the active directory.
gp_encrypt = gp %>% select(-c(name, address1, address2, address3)) %>% encrypt(postcode, telephone, lookup = TRUE) #> Lookup table object created with name 'lookup' #> Lookup table written to file with name 'lookup.csv' gp_encrypt #> A tibble: 1,212 x 7 #> key organisation_code city county opendate #> <int> <chr> <chr> <chr> <date> #> 1 1 S10002 DUNDEE ANGUS 1995-05-01 #> 2 2 S10017 CRIEFF PERTHSHIRE 1996-04-06
The file creation can be turned off with
write_lookup = FALSE and the name of the lookup can be changed with
lookup_name = "anyNameHere".
The created lookup file should be itself encrypted using the method below.
Decryption is performed by passing the lookup object or file to the
gp_encrypt %>% decrypt(postcode, telephone, lookup_object = lookup) # Or gp_encrypt %>% decrypt(postcode, telephone, lookup_path = "lookup.csv") #> A tibble: 1,212 x 8 #> postcode telephone organisation_code city county opendate #> <chr> <chr> <chr> <chr> <chr> <date> #> 1 DD2 5NH 01382 580264 S10002 DUNDEE ANGUS 1995-05-01 #> 2 PH7 3SA 01764 652283 S10017 CRIEFF PERTHSHIRE 1996-04-06