Sha256: 6a601a2bbdbd1184c6411282f403425f6b33c774302cc3eb17030924710a8f7b
Contents?: true
Size: 1.31 KB
Versions: 8
Compression:
Stored size: 1.31 KB
Contents
module Xmlenc module Builder class EncryptedKey include Xmlenc::Builder::ComplexTypes::EncryptedType 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 } tag "EncryptedKey" namespace "xenc" attribute :id, String, tag: 'Id' attribute :recipient, String, tag: 'Recipient' has_one :reference_list, Xmlenc::Builder::ReferenceList, :xpath => "./" attr_accessor :data def encrypt(key, data = nil) encryptor = algorithm.new(key) encrypted = encryptor.encrypt(data || self.data) cipher_data.cipher_value = Base64.encode64(encrypted) end def add_data_reference(data_id) self.reference_list ||= ReferenceList.new self.reference_list.add_data_reference(data_id) end def initialize(*args) options = args.extract_options! @recipient = options.delete(:recipient) @id = options.delete(:id) super(*(args << options)) end private def algorithm algorithm = encryption_method.algorithm ALGORITHMS[algorithm] || raise(UnsupportedError.new("Unsupported encryption method #{algorithm}")) end end end end
Version data entries
8 entries across 8 versions & 1 rubygems