Class: Xmlenc::Builder::EncryptedData
- Inherits:
-
Object
- Object
- Xmlenc::Builder::EncryptedData
- Includes:
- ComplexTypes::EncryptedType
- Defined in:
- lib/xmlenc/builder/encrypted_data.rb
Constant Summary collapse
- ALGORITHMS =
{ 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc' => Algorithms::DES3CBC, 'http://www.w3.org/2001/04/xmlenc#aes128-cbc' => Algorithms::AESCBC[128], 'http://www.w3.org/2001/04/xmlenc#aes256-cbc' => Algorithms::AESCBC[256], 'http://www.w3.org/2009/xmlenc11#aes128-gcm' => Algorithms::AESGCM[128], 'http://www.w3.org/2009/xmlenc11#aes192-gcm' => Algorithms::AESGCM[192], 'http://www.w3.org/2009/xmlenc11#aes256-gcm' => Algorithms::AESGCM[256] }
- TYPES =
{ 'http://www.w3.org/2001/04/xmlenc#Element' => :element, 'http://www.w3.org/2001/04/xmlenc#Content' => :content, }
Instance Method Summary collapse
- #encrypt(data, key_options = {}) ⇒ Object
-
#initialize(*args) ⇒ EncryptedData
constructor
A new instance of EncryptedData.
- #set_key_name(key_name) ⇒ Object
- #set_key_retrieval_method(retrieval_method) ⇒ Object
- #type ⇒ Object
Methods included from ComplexTypes::EncryptedType
Constructor Details
#initialize(*args) ⇒ EncryptedData
Returns a new instance of EncryptedData.
29 30 31 32 33 34 35 36 37 |
# File 'lib/xmlenc/builder/encrypted_data.rb', line 29 def initialize(*args) = args. if .key?(:id) self.id = .delete(:id) else self.id = "_#{SecureRandom.hex(5)}" end super(*(args << )) end |
Instance Method Details
#encrypt(data, key_options = {}) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/xmlenc/builder/encrypted_data.rb', line 39 def encrypt(data, = {}) encryptor = algorithm.setup encrypted = encryptor.encrypt(data, :node => encryption_method) cipher_data.cipher_value = Base64.encode64(encrypted) key_params = { :data => encryptor.key } encrypted_key = EncryptedKey.new(key_params.merge()) encrypted_key.add_data_reference(id) if [:carried_key_name].present? encrypted_key.carried_key_name = [:carried_key_name] end encrypted_key end |
#set_key_name(key_name) ⇒ Object
63 64 65 66 67 68 |
# File 'lib/xmlenc/builder/encrypted_data.rb', line 63 def set_key_name(key_name) if key_name self.key_info ||= KeyInfo.new self.key_info.key_name = key_name end end |
#set_key_retrieval_method(retrieval_method) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/xmlenc/builder/encrypted_data.rb', line 56 def set_key_retrieval_method(retrieval_method) if retrieval_method self.key_info ||= KeyInfo.new self.key_info.retrieval_method = retrieval_method end end |
#type ⇒ Object
25 26 27 |
# File 'lib/xmlenc/builder/encrypted_data.rb', line 25 def type 'http://www.w3.org/2001/04/xmlenc#Element' end |