Hat*_*e35 2 sqlite hash r password-protection shiny
我正在编写一个 R Shiny 应用程序,最终将上线。该应用程序的一部分需要密码保护。只有拥有正确密码的人才能在应用程序上添加某些信息。现在我的做法如下:
我的问题是这种方法是否存在安全缺陷?有一个更好的方法吗?
我不太熟悉人们在网上可以访问哪些用于创建闪亮应用程序的代码或数据库,这就是为什么我不确定这是否是一个好方法。
谢谢!
你走在正确的轨道上。我的建议是使用一个包来处理您的散列/加密,并加密您的数据。
方法是:
这提供了相当高的安全级别,对于公司的仪表板来说足够好,但对于医疗记录来说还不够好。
始终假设人们可以查看闪亮应用程序背后的代码和数据。这包括在没有密码或密码存储在应用程序中时手动运行数据库查询。
library(shiny)
library(sodium)
ui <- fluidPage(
passwordInput("txt_password", "Enter Password"),
actionButton("btn_action", "Submit")
)
server <- function(input, output, session) {
#Load encrypted data
data_encrypted <- readRDS("data_encrypted.rds")
#Create a reactive dataframe to store the unencyrpted data
reactives <- reactiveValues(data_unencrypted = NULL)
#Public key (its okay to hardcode it here, public keys are designed for sharing)
key_public <- "e5 c2 cb 08 27 41 26 1a 06 ad 9f 6a c9 29 ad 37 f0 66 f1 cd b7 f7 1e 24 e9 8b 26 8e 81 b6 68 16"
#Observe submit button (runs once when submit button is clicked)
observeEvent(input$btn_action, {
#Private key
key_private <- sha256(charToRaw(input$txt_password))
#Check if private key provided is correct
if(paste(pubkey(key_private), collapse = " ") == key_public) {
showNotification("Correct password")
#Unencrypt data and make it available elsewhere
reactives$data_unencrypted <- unserialize(simple_decrypt(data_encrypted, key_private))
#Print data to the console, so we can check it worked
print(reactives$data_unencrypted )
} else {
showNotification("Incorrect password")
}
})
#Remove all data when session ends
cancel.onSessionEnded <- session$onSessionEnded(function() {
rm(list = ls())
})
}
shinyApp(ui, server)
Run Code Online (Sandbox Code Playgroud)
以下代码显示了如何在上传应用程序之前加密数据:
library(sodium)
#Your password
mysupersecretpassword <- "abc"
#Your data
data_unencrypted <- data.frame(id = seq(1:10))
#Private key
key_private <- sha256(charToRaw(mysupersecretpassword))
paste("Private Key:", paste(key_private, collapse = " "))
#Public key
key_public <- pubkey(key_private)
paste("Public Key:", paste(key_public, collapse = " "))
#Encrypt data
data_encrypted <- simple_encrypt(serialize(data_unencrypted, NULL), key_public)
#Save data
saveRDS(data_encrypted, "data_encrypted.rds")
#Cleanup
rm(list=ls())
Run Code Online (Sandbox Code Playgroud)