当前位置: 首页>>代码示例>>PHP>>正文


PHP Utilities::ctrCrypt方法代码示例

本文整理汇总了PHP中WindowsAzure\Common\Internal\Utilities::ctrCrypt方法的典型用法代码示例。如果您正苦于以下问题:PHP Utilities::ctrCrypt方法的具体用法?PHP Utilities::ctrCrypt怎么用?PHP Utilities::ctrCrypt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在WindowsAzure\Common\Internal\Utilities的用法示例。


在下文中一共展示了Utilities::ctrCrypt方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testIngestEncryptedAssetAndDecryptAtAzure

 public function testIngestEncryptedAssetAndDecryptAtAzure()
 {
     // Setup
     $content = TestResources::MEDIA_SERVICES_DUMMY_FILE_CONTENT;
     $aesKey = Utilities::generateCryptoKey(32);
     $protectionKeyId = $this->restProxy->getProtectionKeyId(ProtectionKeyTypes::X509_CERTIFICATE_THUMBPRINT);
     $protectionKey = $this->restProxy->getProtectionKey($protectionKeyId);
     $contentKey = new ContentKey();
     $contentKey->setContentKey($aesKey, $protectionKey);
     $contentKey->setProtectionKeyId($protectionKeyId);
     $contentKey->setProtectionKeyType(ProtectionKeyTypes::X509_CERTIFICATE_THUMBPRINT);
     $contentKey->setContentKeyType(ContentKeyTypes::STORAGE_ENCRYPTION);
     $contentKey = $this->createContentKey($contentKey);
     $asset = new Asset(Asset::OPTIONS_STORAGE_ENCRYPTED);
     $asset->setName(TestResources::MEDIA_SERVICES_ASSET_NAME . $this->createSuffix());
     $asset = $this->createAsset($asset);
     $this->restProxy->linkContentKeyToAsset($asset, $contentKey);
     $initializationVector = Utilities::generateCryptoKey(8);
     $encrypted = Utilities::ctrCrypt($content, $aesKey, str_pad($initializationVector, 16, chr(0)));
     // Test
     $access = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix());
     $access->setDurationInMinutes(30);
     $access->setPermissions(AccessPolicy::PERMISSIONS_WRITE);
     $access = $this->createAccessPolicy($access);
     $locator = new Locator($asset, $access, Locator::TYPE_SAS);
     $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix());
     $locator->setStartTime(new \DateTime('now -5 minutes'));
     $locator = $this->createLocator($locator);
     $fileName = TestResources::MEDIA_SERVICES_DUMMY_FILE_NAME;
     $this->restProxy->uploadAssetFile($locator, $fileName, $encrypted);
     $this->restProxy->createFileInfos($asset);
     $files = $this->restProxy->getAssetAssetFileList($asset);
     $files[0]->setIsEncrypted(true);
     $files[0]->setEncryptionKeyId($contentKey->getId());
     $files[0]->setEncryptionScheme(EncryptionSchemes::STORAGE_ENCRYPTION);
     $files[0]->setEncryptionVersion(Resources::MEDIA_SERVICES_ENCRYPTION_VERSION);
     $files[0]->setInitializationVector(Utilities::base256ToDec($initializationVector));
     $this->restProxy->updateAssetFile($files[0]);
     $decodeProcessor = $this->restProxy->getLatestMediaProcessor(TestResources::MEDIA_SERVICES_DECODE_PROCESSOR_NAME);
     $task = new Task(TestResources::getMediaServicesTask($this->getOutputAssetName()), $decodeProcessor->getId(), TaskOptions::NONE);
     $job = new Job();
     $job->setName(TestResources::MEDIA_SERVICES_JOB_NAME . $this->createSuffix());
     $job = $this->createJob($job, array($asset), array($task));
     $this->waitJobStatus($job, array(Job::STATE_FINISHED, Job::STATE_ERROR));
     $this->assertEquals($this->restProxy->getJobStatus($job), Job::STATE_FINISHED);
     $outputAssets = $this->restProxy->getJobOutputMediaAssets($job);
     $this->assertCount(1, $outputAssets);
     $accessPolicy = new AccessPolicy(TestResources::MEDIA_SERVICES_ACCESS_POLICY_NAME . $this->createSuffix());
     $accessPolicy->setDurationInMinutes(300);
     $accessPolicy->setPermissions(AccessPolicy::PERMISSIONS_READ);
     $accessPolicy = $this->createAccessPolicy($accessPolicy);
     $locator = new Locator($outputAssets[0], $accessPolicy, Locator::TYPE_SAS);
     $locator->setName(TestResources::MEDIA_SERVICES_LOCATOR_NAME . $this->createSuffix());
     $locator->setStartTime(new \DateTime('now -5 minutes'));
     $locator = $this->createLocator($locator);
     // without sleep() Locator hasn't enough time to create URL, so that's why we have to use at least sleep(30)
     sleep(40);
     $method = Resources::HTTP_GET;
     $url = new Url($locator->getBaseUri() . '/' . TestResources::MEDIA_SERVICES_DUMMY_FILE_NAME . $locator->getContentAccessComponent());
     $filters = array();
     $statusCode = Resources::STATUS_OK;
     $httpClient = new HttpClient();
     $httpClient->setMethod($method);
     $httpClient->setExpectedStatusCode($statusCode);
     $actual = $httpClient->send($filters, $url);
     $this->assertEquals($content, $actual);
 }
开发者ID:bitmovin,项目名称:azure-sdk-for-php,代码行数:67,代码来源:MediaServicesFunctionalTest.php

示例2: testCtrCryptInvalidInitializationVectorLength

 /**
  * @covers WindowsAzure\Common\Internal\Utilities::ctrCrypt
  */
 public function testCtrCryptInvalidInitializationVectorLength()
 {
     // Setup
     $data = 'Test data more than 16 bytes';
     $key = Utilities::generateCryptoKey(32);
     $initializationVector = '1234';
     $this->setExpectedException(get_class(new \InvalidArgumentException('')));
     // Test
     $actual = Utilities::ctrCrypt($data, $key, $initializationVector);
 }
开发者ID:southworkscom,项目名称:azure-sdk-for-php,代码行数:13,代码来源:UtilitiesTest.php


注:本文中的WindowsAzure\Common\Internal\Utilities::ctrCrypt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。