wapacro / az-keyvault-php
使用托管标识与 Azure KeyVault 一起工作的 PHP 库
v2.2.0
2021-04-25 13:32 UTC
Requires
- ext-gmp: *
- ext-json: *
- brick/math: ^0.9.1
- guzzlehttp/guzzle: ^7.0
- spatie/url: ^1.3
- web-token/jwt-core: ^2.0
Requires (Dev)
- ext-openssl: *
- friendsofphp/php-cs-fixer: ^2.16
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2024-09-19 22:39:25 UTC
README
此库允许轻松将 Azure Key Vault 集成到 PHP 应用程序中。
亮点
- 内置托管标识支持
为您的应用程序设置托管标识,并将所有密钥、密钥和证书集中存储在 Azure Key Vault 中。直接从代码中安全访问,无需担心凭据。 - 易于使用的 API
此库的 API 简单易懂。在 Azure 中进行一些设置,并编写几行代码,您就可以开始使用了! - 与基于 Windows 和 Linux 的应用程序服务计划以及虚拟机一起工作
如何使用
三步即可开始!
- 向您的 Azure 应用服务添加系统分配的标识,并授权应用程序从密钥存储库读取和列出密钥
- 使用 Composer 在项目中安装此包
composer require wapacro/az-keyvault-php
- 使用简单的 API 访问密钥存储库中的密钥和证书
<?php /** * Secrets */ $secret = new AzKeyVault\Secret('https://my-keyvault-dns.vault.azure.net'); // If you want to get all secrets (default max to 25): $secrets = $secret->getSecrets(); // ... else get next page via nextLink $secrets = $secret->getSecrets($secrets->getNextLink()); // If you want the latest secret $value = $secret->getSecret('mySecretName'); // If you want a specific secret version: $value = $secret->getSecret('mySecretName', '9fe63d32-5eb0-47f2-8ef8-version-id'); // ... otherwise get all versions of secret // with name "mySecretName" which are marked // as enabled and retrieve the first one $enabledSecretVersions = $secret->getSecretVersions('mySecretName')->enabled(); $firstEnabledVersion = reset($enabledSecretVersions); $value = $secret->getSecret($firstEnabledVersion); echo $value->secret; // prints: my super secret message // If you want to set secret or update secret with newer version: $value = $secret->setSecret('mySecretName', 'mySecretValue'); echo $value->secret; // prints: mySecretValue /** * Keys */ $key = new AzKeyVault\Key('https://my-keyvault-dns.vault.azure.net'); // Retrieve specific key version: $value = $key->getKey('myKeyName', 'j7d8rd32-5eb0-47f2-8ef8-version-id'); // ... or get all versions of a key // and retrieve the first one which // is enabled, just like with the // secrets above $enabledKeyVersions = $key->getKeyVersions('myKeyName')->enabled(); $firstEnabledVersion = reset($enabledKeyVersions); $value = $key->getKey($firstEnabledVersion); echo $value->type; // e.g. "RSA" echo $value->n; // prints base64 encoded RSA modulus // This library also provides some key utilities // to make retrieved keys work with the OpenSSL extension $pem = (new AzKeyVault\KeyUtil($value))->toPEM(); $keyDetails = openssl_pkey_get_details(openssl_pkey_get_private($pem)); var_dump($keyDetails);
注意: KeyUtil
支持 RSA 和 EC 密钥
计划中的功能
- 访问证书