Class: Xmlenc::Builder::EncryptedKey

Inherits:
Object
  • Object
show all
Includes:
ComplexTypes::EncryptedType
Defined in:
lib/xmlenc/builder/encrypted_key.rb

Constant Summary collapse

ALGORITHMS =
{
    'http://www.w3.org/2001/04/xmlenc#rsa-1_5'        => Algorithms::RSA15,
    'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p' => Algorithms::RsaOaepMgf1p
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ComplexTypes::EncryptedType

#set_encryption_method, #set_key_name

Constructor Details

#initialize(*args) ⇒ EncryptedKey

Returns a new instance of EncryptedKey.



34
35
36
37
38
39
# File 'lib/xmlenc/builder/encrypted_key.rb', line 34

def initialize(*args)
  options = args.extract_options!
  @recipient = options.delete(:recipient)
  @id = options.delete(:id)
  super(*(args << options))
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



21
22
23
# File 'lib/xmlenc/builder/encrypted_key.rb', line 21

def data
  @data
end

Instance Method Details

#add_data_reference(data_id) ⇒ Object



29
30
31
32
# File 'lib/xmlenc/builder/encrypted_key.rb', line 29

def add_data_reference(data_id)
  self.reference_list ||= ReferenceList.new
  self.reference_list.add_data_reference(data_id)
end

#encrypt(key, data = nil) ⇒ Object



23
24
25
26
27
# File 'lib/xmlenc/builder/encrypted_key.rb', line 23

def encrypt(key, data = nil)
  encryptor = algorithm.new(key)
  encrypted = encryptor.encrypt(data || self.data)
  cipher_data.cipher_value = Base64.encode64(encrypted)
end