首页 \ 问答 \ Spring Boot - 加密JSON数据(Spring Boot - Encrypt JSON data)

Spring Boot - 加密JSON数据(Spring Boot - Encrypt JSON data)

在我们的应用程序中,我们必须为每个请求和响应加密/解密Json属性值(而不是属性名称)。 例,
{"userName":"encrypted value", "email":"encrypted value"}

我们使用Sprint引导1.3,我们使用@RequestBody@ResponseBody注释将请求json与对象绑定,并将响应对象序列化为JSON。

我们不想在我们的每个控制器方法中调用加密/解密方法。 有什么方法可以指示Sprint在绑定请求对象之前解密json值? 同样,要将响应对象字段值在转换为json之前加密? 或者定制杰克逊可能会帮助我们?

谢谢!


In our application we have to encrypt/decrypt the Json property values (not the property name) for each request and response. Example,
{"userName":"encrypted value", "email":"encrypted value"}

We use Sprint boot 1.3 and we are using @RequestBody and @ResponseBody annotations to bind the request json with the object and serialise the response object as JSON.

We don't want to call encrypt/decrypt method in our each controller method. Is there any way we can instruct sprint to decrypt the json values before binding with the request object? Similarly, to encrypt the response object field values before converting them to json? Or customising Jackson may help us?

Thanks!


原文:https://stackoverflow.com/questions/40740771
更新时间:2023-08-30 11:08

最满意答案

当您使用Gemfile ,您正在使用bundler。 在您的脚本中,您需要包含rubygemsbundler才能使其正常工作。 试试这个

require 'rubygems'
require 'bundler/setup'

require 'linkedindata'

l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)

你已经运行了bundle install ,抱歉不熟悉gemrat,所以不确定它对你有多大帮助。

如果你实际上没有使用bundler ,只需从上面的代码中删除require 'bundler/setup' ,你仍然需要在脚本中需要rubygems。

在看起来像宝石本身有点破坏它声明依赖关系的方式,以及它所依赖的其他宝石。 我似乎能够使其工作如下:

的Gemfile:

source 'https://rubygems.org'
gem 'linkedin-scraper'
gem 'linkedindata'
gem 'generalscraper'
gem 'uploadconvert'
gem 'docsplit'
gem 'crack'
gem 'pry'
gem 'activesupport'
gem 'selenium-webdriver'

它似乎还需要linkedin-scraper作为linkedin_scraper但不确定为什么会这样。 所以编辑。

{GEMPATH}/linkedindata-0.0.22/lib/linkedindata.rb require 'linkedin_scraper'而不是require 'linkedin-scraper'似乎使它工作。

所以用上面的更改并使用bundler

require 'rubygems'
require 'bundler/setup'
require 'linkedindata'
l = LinkedinData.new(1, "proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)

现在运行(我没有proxylist.txt所以它爆炸寻找它,但它不再得到库错误)。


As you are using a Gemfile, you are using bundler. In your script you will need to include rubygems and bundler to make it work. Try this

require 'rubygems'
require 'bundler/setup'

require 'linkedindata'

l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)

You have run bundle install, sorry not familiar with gemrat, so not sure how much it does for you.

if you are not actually using bundler, just remove require 'bundler/setup' from the code above, you will still need to require rubygems though in your script.

in looks like the gem itself is kind of broken in the way it declare dependencies, and the other gems that it relies on. I appear to be able to make it work as follows:

Gemfile:

source 'https://rubygems.org'
gem 'linkedin-scraper'
gem 'linkedindata'
gem 'generalscraper'
gem 'uploadconvert'
gem 'docsplit'
gem 'crack'
gem 'pry'
gem 'activesupport'
gem 'selenium-webdriver'

It also appears that it the linkedin-scraper needs to required as linkedin_scraper but not sure why that is. So editing.

{GEMPATH}/linkedindata-0.0.22/lib/linkedindata.rb to require 'linkedin_scraper' as opposed to require 'linkedin-scraper' seems to make it work.

So with the above changes and using bundler

require 'rubygems'
require 'bundler/setup'
require 'linkedindata'
l = LinkedinData.new(1, "proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)

now runs (I don't have a proxylist.txt so it blows up looking for it, but it doesn't get anymore library errors).

相关问答

更多
  • 当您使用Gemfile ,您正在使用bundler。 在您的脚本中,您需要包含rubygems和bundler才能使其正常工作。 试试这个 require 'rubygems' require 'bundler/setup' require 'linkedindata' l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true) searchTerms = ['First', 'Second', 'Third'] l.getByKeywor ...
  • 为了获得良好的开端,您可以使用bundle gem命令和rspec --init 。 ~/code $ bundle gem my_lib create my_lib/Gemfile create my_lib/Rakefile create my_lib/LICENSE.txt create my_lib/README.md create my_lib/.gitignore create my_lib/my_lib.gem ...
  • 没有。 这种语言发展很多,与Ruby最近有很大的不同。 虽然感觉有点像Ruby,但如果你真的尝试过,你很快就会明白为什么这个问题甚至不会出现,除了你可以想象的最简单的宝石。 只有两个例子: Crystal没有单引号字符串文字: 'c' # Ok in Ruby and Crystal, but different things, # a String in Ruby, a Char in Crystal "a string" # Ok in Ruby and Cryst ...
  • OP在评论中表示: 实际上,检查应用程序/更新它似乎我的Xcode已更新。 但是我没有升级到约塞米蒂。 升级到Apple的Xcode可以以惊人的方式破解事物。 每当更新Xcode或升级OS X系统库时,它通常可以帮助执行以下部分或全部操作: 接受新的Xcode许可协议。 即使您之前已经接受了协议,也需要在每次升级后执行此操作。 再次安装Xcode命令行工具。 重新安装任何非系统Ruby版本,并使用本机扩展重新编译gem。 In comments, the OP said: Actually, checkin ...
  • 你有没有通过shell中的“gem install curb”安装gem? 前两个,Net :: HTTP和JSON,是Ruby 1.9标准库的一部分,因此它们实际上根本不使用RubyGems。 Have you installed the gem via "gem install curb" in the shell? The first two, Net::HTTP and JSON, are part of the Ruby 1.9 standard library, so they don't ac ...
  • 正如Jesper建议的那样,我使用Dalli memcached客户端解决了这个问题。 As Jesper suggested, I solved the issue using Dalli memcached client.
  • 使用类似于适用于ADFS服务器的Ruby on Rails的SAML工具包之类的东西,您可以与ADFS集成。 现在您可以利用ADFS功能: 通过Azure ACS与Facebook等界面 与Azure Active Directory的接口以及SSO到SaaS应用程序的接口 Azure Active Directory多重身份验证 BYOD通过Web应用程序代理 ADFS 3.0上的OAuth 等等。 该名单一直在扩大。 一旦你加入这些标准。 您只需在发布时继承所有新功能。 Using something ...
  • 由于我过去使用过旧的Ruby版本2.0,所以它让apache感到困惑。 我可以明确地告诉apache使用哪个目录,或者使用RVM(Ruby Version Manager)来完成所有工作。 只需要完成以下步骤: 安装RVM: rvm get stable --auto-dotfiles 然后告诉您倾向于使用哪个版本: rvm use 2.2.0 更新宝石 gem install rails 现在准备好了! Since I had an older Ruby version 2.0 from the p ...
  • 我想,你正在使用指挥官宝石。 请安装 gem install commander 版本是4.1.1 I guess, You are using commander gem. Please install it by gem install commander Version is 4.1.1
  • 从我自己的实验和调查来看,很难确定什么是“必需的”和什么是可选的。 有些文件看起来非常安全且易于删除,而有些文件我不想玩。 我的结果只能节省大约5 MB ...可能还不足以保证这样做。 箱子 ruby/bin目录包含许多批处理脚本,它们只是用正确的“应用程序”调用ruby可执行文件的助手,如Rake或Gem。 例如, rake.bat包含此行 @"%~dp0ruby.exe" "%~dpn0" %* 您可以在build.bat脚本中使用正确的comamnd替换它(假设它比ruby环境高一级,可能在解决方案 ...

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)