Class: SamlIdp::Encryptor
- Inherits:
-
Object
- Object
- SamlIdp::Encryptor
- Defined in:
- lib/saml_idp/encryptor.rb
Instance Attribute Summary collapse
-
#block_encryption ⇒ Object
Returns the value of attribute block_encryption.
-
#cert ⇒ Object
Returns the value of attribute cert.
-
#encryption_key ⇒ Object
Returns the value of attribute encryption_key.
-
#key_transport ⇒ Object
Returns the value of attribute key_transport.
Instance Method Summary collapse
- #encrypt(raw_xml) ⇒ Object
-
#initialize(opts) ⇒ Encryptor
constructor
A new instance of Encryptor.
Constructor Details
#initialize(opts) ⇒ Encryptor
Returns a new instance of Encryptor.
9 10 11 12 13 |
# File 'lib/saml_idp/encryptor.rb', line 9 def initialize(opts) self.block_encryption = opts[:block_encryption] self.key_transport = opts[:key_transport] self.cert = opts[:cert] end |
Instance Attribute Details
#block_encryption ⇒ Object
Returns the value of attribute block_encryption.
5 6 7 |
# File 'lib/saml_idp/encryptor.rb', line 5 def block_encryption @block_encryption end |
#cert ⇒ Object
Returns the value of attribute cert.
7 8 9 |
# File 'lib/saml_idp/encryptor.rb', line 7 def cert @cert end |
#encryption_key ⇒ Object
Returns the value of attribute encryption_key.
4 5 6 |
# File 'lib/saml_idp/encryptor.rb', line 4 def encryption_key @encryption_key end |
#key_transport ⇒ Object
Returns the value of attribute key_transport.
6 7 8 |
# File 'lib/saml_idp/encryptor.rb', line 6 def key_transport @key_transport end |
Instance Method Details
#encrypt(raw_xml) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/saml_idp/encryptor.rb', line 15 def encrypt(raw_xml) encryption_template = Nokogiri::XML::Document.parse(build_encryption_template).root encrypted_data = Xmlenc::EncryptedData.new(encryption_template) @encryption_key = encrypted_data.encrypt(raw_xml) encrypted_key_node = encrypted_data.node.at_xpath( '//xenc:EncryptedData/ds:KeyInfo/xenc:EncryptedKey', Xmlenc::NAMESPACES ) encrypted_key = Xmlenc::EncryptedKey.new(encrypted_key_node) encrypted_key.encrypt(openssl_cert.public_key, encryption_key) xml = Builder::XmlMarkup.new xml.EncryptedAssertion xmlns: Saml::XML::Namespaces::ASSERTION do |enc_assert| enc_assert << encrypted_data.node.to_s end end |