Sha256: 8f4da4fb3158cc629256e569f9aeba383d7319e5ce37ae2ff327f2f7ee782e8e

Contents?: true

Size: 1.01 KB

Versions: 8

Compression:

Stored size: 1.01 KB

Contents

module Xml
  module Kit
    class Encryption
      attr_reader :asymmetric_algorithm
      attr_reader :asymmetric_cipher_value
      attr_reader :symmetric_algorithm
      attr_reader :symmetric_cipher_value

      def initialize(
        raw_xml,
        public_key,
        symmetric_algorithm: ::Xml::Kit::Crypto::SymmetricCipher::DEFAULT_ALGORITHM,
        asymmetric_algorithm: ::Xml::Kit::Crypto::RsaCipher::ALGORITHM
      )
        @symmetric_algorithm = symmetric_algorithm
        @symmetric_cipher_value = Base64.encode64(symmetric_cipher.encrypt(raw_xml))

        @asymmetric_algorithm = asymmetric_algorithm
        @asymmetric_cipher_value = Base64.encode64(public_key.public_encrypt(symmetric_cipher.key))
      end

      def to_xml(xml: ::Builder::XmlMarkup.new)
        ::Xml::Kit::Template.new(self).to_xml(xml: xml)
      end

      private

      def symmetric_cipher
        @symmetric_cipher ||= ::Xml::Kit::Crypto::SymmetricCipher.new(
          symmetric_algorithm
        )
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
xml-kit-0.1.8 lib/xml/kit/encryption.rb
xml-kit-0.1.7 lib/xml/kit/encryption.rb
xml-kit-0.1.6 lib/xml/kit/encryption.rb
xml-kit-0.1.5 lib/xml/kit/encryption.rb
xml-kit-0.1.4 lib/xml/kit/encryption.rb
xml-kit-0.1.3 lib/xml/kit/encryption.rb
xml-kit-0.1.2 lib/xml/kit/encryption.rb
xml-kit-0.1.1 lib/xml/kit/encryption.rb