Class: Saml::Elements::EncryptedID

Inherits:
Object
  • Object
show all
Includes:
HappyMapper, Base, XMLHelpers
Defined in:
lib/saml/elements/encrypted_id.rb

Instance Method Summary collapse

Methods included from XMLHelpers

#add_signature, #to_soap, #to_xml

Constructor Details

#initialize(*args) ⇒ EncryptedID

Returns a new instance of EncryptedID.



19
20
21
22
# File 'lib/saml/elements/encrypted_id.rb', line 19

def initialize(*args)
  options = args.extract_options!
  super(*(args << options))
end

Instance Method Details

#encrypt(key_descriptor, key_options = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/saml/elements/encrypted_id.rb', line 24

def encrypt(key_descriptor, key_options = {})
  certificate = key_descriptor.certificate
  key_name = key_descriptor.key_info.key_name

  self.encrypted_data = Xmlenc::Builder::EncryptedData.new
  self.encrypted_data.set_key_retrieval_method Xmlenc::Builder::RetrievalMethod.new(
    uri: "##{key_options[:id]}"
  )
  self.encrypted_data.set_encryption_method(
    algorithm: 'http://www.w3.org/2001/04/xmlenc#aes256-cbc'
  )
  encrypted_key = self.encrypted_data.encrypt(name_id_xml, key_options)
  encrypted_key.set_encryption_method(
    algorithm: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p', 
    digest_method_algorithm: 'http://www.w3.org/2000/09/xmldsig#sha1'
  )
  encrypted_key.set_key_name key_name
  encrypted_key.encrypt certificate.public_key
  self.encrypted_keys = [encrypted_key]
  self.name_id = nil
end