class AzureMediaService::ContentKey

Constants

ContentKeyTypes

Public Class Methods

create(content_key:, content_key_type: 4,protection_key_type: 0, name: nil ) click to toggle source
# File lib/azure_media_service/model/content_key.rb, line 13
def create(content_key:, content_key_type: 4,protection_key_type: 0, name: nil )
  id = "nb:kid:UUID:#{SecureRandom.uuid.upcase}"
  # content_key = SecureRandom.random_bytes(16)
  protection_key_id = service.get_protection_key_id(content_key_type)
  protection_key = service.get_protection_key(protection_key_id) # X.509
  x509 = OpenSSL::X509::Certificate.new(Base64.decode64(protection_key))
  public_key = x509.public_key
  encrypted_content_key = Base64.strict_encode64(public_key.public_encrypt(content_key, OpenSSL::PKey::RSA::PKCS1_OAEP_PADDING))

  # create checksum
  cipher = OpenSSL::Cipher.new('AES-128-ECB')
  cipher.encrypt
  cipher.key = content_key
  cipher.padding = 0
  encrypt_data = ""
  encrypt_data << cipher.update(protection_key_id[0,16])
  encrypt_data << cipher.final
  check_sum = Base64.strict_encode64(encrypt_data[0,8])

  post_body = {
    "Id"                  => id,
    "ContentKeyType"      => content_key_type,
    "EncryptedContentKey" => encrypted_content_key,
    "ProtectionKeyId"     => protection_key_id,
    "ProtectionKeyType"   => protection_key_type,
    "Checksum"            => check_sum,
    "Name"                => name
  }
  create_response(service.post("ContentKeys", post_body))
end
get(content_key_id=nil) click to toggle source
# File lib/azure_media_service/model/content_key.rb, line 44
def get(content_key_id=nil)
  service.get('ContentKeys', ContentKey, content_key_id)
end

Public Instance Methods

add_authorization_policy(policy_id) click to toggle source
# File lib/azure_media_service/model/content_key.rb, line 49
def add_authorization_policy(policy_id)
  res = @request.put("ContentKeys('#{CGI.escape(self.Id)}')", {AuthorizationPolicyId: policy_id})
end
delete() click to toggle source
# File lib/azure_media_service/model/content_key.rb, line 61
def delete
  begin 
    res = @request.delete("ContentKeys('#{self.Id}')")
    clear_cache
  rescue => e
    raise MediaServiceError.new(e.message)
  end
  res
end
get_key_delivery_url(key_delivery_type) click to toggle source

GetKeyDeliveryUrl

@params key_delivery_type 1: PlayReady license 2: EnvelopeEncryption

# File lib/azure_media_service/model/content_key.rb, line 57
def get_key_delivery_url(key_delivery_type)
  @request.post("ContentKeys('#{CGI.escape(self.Id)}')/GetKeyDeliveryUrl", {KeyDeliveryType: key_delivery_type})
end