小编Cra*_*ger的帖子

mongoid文档to_json包括所有嵌入文档,每个文档没有':include'

给定一个任意mongoid文档如何将其转换为JSON并包含任何嵌入式结构,而不是在我的to_json语句中特别包含这些结构.

例如:

#!/usr/bin/env ruby
require 'mongoid'
require 'json'
require 'pp'

class Doc
  include Mongoid::Document
  include Mongoid::Timestamps

  field :doc_specific_info    , type: String 

  embeds_many :persons
end

class Person
  include Mongoid::Document

  field :role                  , type: String
  field :full_name             , type: String

  embeds_many :addresses
  embedded_in :Doc
end

class Address
  include Mongoid::Document

  field :full_address       , type: String

end

doc = Doc.new
doc.doc_specific_info = "TestReport"

p = Person.new
p.role = 'buyer'
p.full_name = 'JOHN DOE'
doc.persons << p

a = Address.new
a.full_address =  '1234 nowhere ville' …
Run Code Online (Sandbox Code Playgroud)

ruby json mongoid

8
推荐指数
1
解决办法
5703
查看次数

AES 的衍生 IV

如果每次在各方之间进行交易时都会生成一个新的随机 AES 密钥。IV是否从密钥派生有关系吗?

例如:Bob 向 Alice 发送一条 AES-CBC 加密消息。Bob 为此创建了一个随机的 256 位密钥。现在假设 Bob 使用 sha256(key) 的前 128 位来获得用于加密的 IV。

Bob 使用 Alice 的公钥通过 RSA 加密来保护密钥。现在 Alice 使用她的 RSA 私钥解密密钥。然后 Alice 使用 sha256(key) 的前 128 位获得 IV 用于解密。

Alice 和 Bob 继续使用相同的程序交谈,但每次发送消息时都会生成一个新的随机密钥。

现在假设 Eve 可以读取 Bob 和 Alice 的 AES 和 RSA 密文。Eve 也知道 Bob 和 Alice 正在从密钥和使用的方法中推导出 IV。那仍然无助于 Eve 破解消息?

encryption rsa aes

1
推荐指数
1
解决办法
1017
查看次数

标签 统计

aes ×1

encryption ×1

json ×1

mongoid ×1

rsa ×1

ruby ×1