Class: AzureMediaService::ContentKey
- Inherits:
-
Model::Base
- Object
- OpenStruct
- Model::Base
- AzureMediaService::ContentKey
- Defined in:
- lib/azure_media_service/model/content_key.rb
Constant Summary collapse
- ContentKeyTypes =
{ CommonEncryption: 0, StorageEncryption: 1, ConfigurationEncryption: 2, UrlEncryption: 3, EnvelopeEncryption: 4 }
Instance Attribute Summary
Attributes inherited from Model::Base
Class Method Summary collapse
- .create(content_key:, content_key_type: 4, protection_key_type: 0, name: nil) ⇒ Object
- .get(content_key_id = nil) ⇒ Object
Instance Method Summary collapse
- #add_authorization_policy(policy_id) ⇒ Object
- #delete ⇒ Object
-
#get_key_delivery_url(key_delivery_type) ⇒ Object
GetKeyDeliveryUrl.
Methods inherited from Model::Base
create_response, #initialize, service
Constructor Details
This class inherits a constructor from AzureMediaService::Model::Base
Class Method Details
.create(content_key:, content_key_type: 4, protection_key_type: 0, name: nil) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# 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) ⇒ Object
44 45 46 |
# 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 |
Instance Method Details
#add_authorization_policy(policy_id) ⇒ Object
49 50 51 |
# File 'lib/azure_media_service/model/content_key.rb', line 49 def (policy_id) res = @request.put("ContentKeys('#{CGI.escape(self.Id)}')", {AuthorizationPolicyId: policy_id}) end |
#delete ⇒ Object
61 62 63 64 65 66 67 68 69 |
# 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.) end res end |
#get_key_delivery_url(key_delivery_type) ⇒ Object
GetKeyDeliveryUrl
57 58 59 |
# 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 |