你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
New-AzureADApplicationKeyCredential
为应用程序创建密钥凭据。
语法
New-AzureADApplicationKeyCredential
-ObjectId <String>
[-CustomKeyIdentifier <String>]
[-StartDate <DateTime>]
[-EndDate <DateTime>]
[-Type <KeyType>]
[-Usage <KeyUsage>]
[-Value <String>]
[-InformationAction <ActionPreference>]
[-InformationVariable <String>]
[<CommonParameters>]
说明
New-AzureADApplicationKeyCredential cmdlet 为应用程序创建密钥凭据。
示例
示例 1:创建新的应用程序密钥凭据
PS C:\> $AppID = (Get-AzureADApplication -Top 1).Objectid
PS C:\> New-AzureADApplicationKeyCredential -ObjectId $AppId -CustomKeyIdentifier "Test" -StartDate "11/7/2016" -Type "Symmetric" -Usage "Sign" -Value "123"
CustomKeyIdentifier : {84, 101, 115, 116}
EndDate : 11/7/2017 12:00:00 AM
KeyId : a5845538-3f67-402d-a03e-36d768f1441e
StartDate : 11/7/2016 12:00:00 AM
Type : Symmetric
Usage : Sign
Value : {49, 50, 51}
第一个命令使用 Get-AzureADApplication cmdlet 获取应用程序的 ID。 命令将其存储在 $AppId 变量中。
第二个命令为 $AppId 标识的应用程序创建应用程序密钥凭据。
示例 2:使用证书添加应用程序密钥凭据
PS C:\> $cer = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2 #create a new certificate object
PS C:\> $cer.Import("C:\Users\PFuller\Desktop\abc.cer")
PS C:\> $bin = $cer.GetRawCertData()
PS C:\> $base64Value = [System.Convert]::ToBase64String($bin)
PS C:\> $bin = $cer.GetCertHash()
PS C:\> $base64Thumbprint = [System.Convert]::ToBase64String($bin)
PS C:\> $keyid = [System.Guid]::NewGuid().ToString()
PS C:\> New-AzureADApplicationKeyCredential -ObjectId 009d786a-3503-4217-b8ab-db03d71c179a -CustomKeyIdentifier $base64Thumbprint -Type AsymmetricX509Cert -Usage Verify -Value $base64Value -StartDate $cer.GetEffectiveDateString() -EndDate $cer.GetExpirationDateString()
前七个命令为应用程序密钥凭据创建值,并将其存储在变量中。
最后一个命令使用证书添加应用程序密钥凭据。
参数
-CustomKeyIdentifier
指定自定义密钥 ID。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-EndDate
指定密钥作为 DateTime 对象变为无效的时间。
类型: | DateTime |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-InformationAction
指定此 cmdlet 如何响应信息事件。
此参数的可接受值为:
- 继续
- 忽略
- 查询
- SilentlyContinue
- 停止
- 挂起
类型: | ActionPreference |
别名: | infa |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-InformationVariable
指定信息变量。
类型: | String |
别名: | iv |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | False |
接受通配符: | False |
-ObjectId
指定 Azure Active Directory 中应用程序的唯一 ID。
类型: | String |
Position: | Named |
默认值: | None |
必需: | True |
接受管道输入: | True |
接受通配符: | False |
-StartDate
指定密钥作为 DateTime 对象生效的时间。
类型: | DateTime |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Type
指定密钥的类型。
类型: | KeyType |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Usage
指定密钥用法。
类型: | KeyUsage |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |
-Value
指定键的值。
类型: | String |
Position: | Named |
默认值: | None |
必需: | False |
接受管道输入: | True |
接受通配符: | False |