简体   繁体   中英

How do I encrypt specific variables/columns in a data frame in R?

我的数据框中有某些变量需要加密,因为其中包含敏感数据。如何加密这些列/变量?

There is a package in R which can do encryption.

An example:

require(PKI)
key <- PKI.genRSAkey(2048)
x <- charToRaw("Hello, world!")
e <- PKI.encrypt(x, key)
y <- PKI.decrypt(e, key)
stopifnot(identical(x, y))
print(rawToChar(y))

which produces an encrypted message of "Hello World" which would be displayed as:

e
[1] 36 83 d3 70 0a 67 b5 05 a6 40 1e 37 28 b9 4e 28 f1 31 92 14 2c 35 c8 8a 61 93 1e 04 62 01 da 3b 2b a0 75 1c 10 58 26
 [40] e4 77 da 7a 47 3f 4e 44 29 8e 97 6f 62 b1 98 44 ba 18 ef 57 1e 9e 9c 27 a8 6e 9c 7b c7 8b c0 c3 a3 00 e2 67 98 8b 6e
 [79] 1a 93 c6 d6 ed 4b 54 e5 7a 07 d7 06 ef a6 bb 36 6a 7f 57 06 b9 15 03 f6 51 3f 07 48 cb f4 2d 25 15 be 42 de f4 8a 06
[118] 72 89 b1 e3 04 d3 ec 80 99 f0 66 0f 84 e1 b5 af 23 24 a1 36 8e 62 65 ae 19 fb 77 d1 36 06 ae 71 95 ee 57 aa 68 5a 6b
[157] 4e 28 ba a2 0d 17 78 11 6c 7f 1b b3 ce 31 65 a9 d3 71 89 76 f9 19 a0 7a bf 02 dd c9 1f cb 9c 39 25 d4 48 a2 23 83 26
[196] b4 a9 b1 40 f5 1d 46 21 35 12 52 73 09 9b f3 52 e1 9e 0d 2a 9b ff 70 81 41 24 49 ed 58 b2 61 dc 3e c9 b3 b2 b1 37 e0
[235] 48 76 18 bf b0 e5 c2 d9 2b 92 2f 6b 49 dd e0 93 b7 10 f8 ba d2 8a

So, similarly, the entire data-frame or the column/row of choice can be encrypted.

This is RSA encryption. In addition, there is the digest package, which helps you create cryptogenic hash objects (recommended); which has the “electronic codebook” (ECB) , “cipher-block chaining” (CBC) and “counter” (CTR) modes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM