如何在Shiny应用程序中加密/解密数据

问题描述 投票:0回答:1

我是加密/解密数据的新手。我在 SQL 表中存储人员详细信息列表,其中一列包含敏感的银行详细信息数据。该表在 Shiny 应用程序中呈现给授权用户。这些用户只能根据具体情况通过 Shiny 应用程序添加、更新和查看此敏感列。他们会点击“添加”或“编辑”来一次更新一个银行详细信息列。

我已经整理好了闪亮的部分以及 SQL 的读写。我想要实现的是,当用户输入银行详细信息时,加密值会写回到 SQL 表中进行保存,并且当他们在 Shiny 应用程序中查看记录时,会显示解密值

我编写了一个虚拟应用程序来模拟这种情况:

library(dplyr)
library(shiny)
library(DT)

ui <- fluidPage(
  # Showing reactive table of all records
  DT::DTOutput("allrecords"),
  
  # Button to allow user to add a new record
  actionButton("add_record_bttn", "Add Record", class = "btn-primary"),
  hr(),
  
  # Form for the user to fill to save new or update existing
  uiOutput("name"),
  uiOutput("bank"),
  uiOutput("save")
  
)

server <- function(input, output, session){
  reactive_val <-
    reactiveValues(
      df_all_records = NULL
    )
  
  
  # Creating table for the sake of example. This is where I would query my SQL table
  name_col <-
    c("Bob", "Jane", "Charlie")
  bank_col <-
    c("ABC", "EDG", "HIJ")
  all_records <- data.frame(name_col, bank_col)
  reactive_val$df_all_records <-
    all_records
  
  # Rendering table
  output$allrecords <-
    DT::renderDT(
    datatable(reactive_val$df_all_records, selection = 'single', rownames = FALSE)
  )
  
  # Showing form when add button is clicked
  observeEvent(input$add_record_bttn, {
    
    output$name <-
      renderUI(textInput("nameGiven", "Enter Name:"))
    output$bank <-
      renderUI(textInput("bankGiven", "Enter Bank:"))
    output$save <-
      renderUI(actionButton("save", "Save Record", class = "btn-success"))
  })
  
  # Appending new row to the table. This is where the I'd write back to SQL table in my actual app
  observeEvent(input$save, {
    
    reactive_val$df_all_records[nrow(reactive_val$df_all_records) + 1,] <- c(input$nameGiven, input$bankGiven)
    print(reactive_val$df_all_records)
  })
  
  # Showing form when and existing record is clicked
  observeEvent(input$allrecords_rows_selected, {
    print(input$allrecords_rows_selected)
    output$name <-
      renderUI(textInput("nameGiven", "Enter Name:", value = reactive_val$df_all_records[input$allrecords_rows_selected, "name_col"]))
    output$bank <-
      renderUI(textInput("bankGiven", "Enter Bank:", value = reactive_val$df_all_records[input$allrecords_rows_selected, "bank_col"]))
    output$save <-
      renderUI(actionButton("save", "Save As New Record", class = "btn-success"))
  })
}

shinyApp(ui = ui, server = server)

表格现在看起来像这样:

enter image description here

我希望它看起来像这样:

enter image description here

当用户添加新记录或单击新记录时,它应该显示实际解密的文本,如下所示:

enter image description here

我需要源头的数据应保存为加密值,而不仅仅是隐藏在前端。

我认为解决方案很简单:)。如有任何帮助,我们将不胜感激!

r encryption shiny hash openssl
1个回答
0
投票

有点晚了,但你找到答案了吗,因为我有非常相似的情况。

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.