Created
March 22, 2024 10:01
-
-
Save jovialcore/476fdf210110b25cb708f6215a9ad139 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Function to create a shared access signature (SAS) token | |
private function getSasToken($accountName, $accountKey, $containerName) | |
{ | |
$sasExpiry = time() + 3600; // Token expires in 1 hour | |
$sasResource = "https://$accountName.blob.core.windows.net/$containerName"; | |
$sasString = utf8_encode(urlencode($sasResource) . "\n$sasExpiry"); | |
$sig = base64_encode(hash_hmac('sha256', $sasString, base64_decode($accountKey), true)); | |
$sasToken = sprintf( | |
'sv=2018-03-28&ss=b&srt=sco&sp=rwdlac&se=%s&st=2020-01-01T00:00:00Z&spr=https&sig=%s', | |
urlencode($sasExpiry), | |
urlencode($sig) | |
); | |
return $sasToken; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment