如何安全地加密 R 中的字符串?

Kev*_* Ho 1 encryption r

如何安全地加密R中的字符串,使其无法进行反向解密?


更新@11/21/2019

我不需要密钥来加密字符串。

目标是即使有人可以查看我的代码和加密字符串,他们也无法检索原始字符串。


我使用的是openssl包,如下所示

library(openssl)

md5("example")
Run Code Online (Sandbox Code Playgroud)

请注意,问题已根据 James 的评论进行了更改,原来的问题是What is the most secure way to encrypt a string in R?

Hug*_*ugh 7

我是以下人士的粉丝sodium

library(sodium)
passkey <- sha256(charToRaw("password123"))
plaintext <- "example"
plaintext.raw <- serialize(plaintext, NULL)
ciphertext <- data_encrypt(plaintext.raw, key = passkey)
unserialize(data_decrypt(ciphertext, key = sha256(charToRaw("password123"))))
#> [1] "example"
Run Code Online (Sandbox Code Playgroud)

由reprex 包(v0.3.0)于 2019-11-22 创建

就是否“最安全”而言,底层方法应该足够好,即使对于高度机密的信息也是如此。但存储、输入或通信方式的安全性passkey可能是弱点。