[英]How to do LDAP query using Powershell and PKI
我是Powershell的新手,我正在嘗試使用PKI身份驗證進行安全的LDAP查詢。 我對如何設置證書和密鑰感到困惑。 基於谷歌搜索/研究,我有一些基礎知識,例如:
$connection = new-object System.DirectoryServices.Protocols.LDAPConnection('$domainName:$portNum')
[string[] $get] = "$attribute1", "$attribute2", "attribute3"
$request = new-object System.DirectoryServices.Protocol.SearchRequest("$targetOu", "$filter", "subtree", $get)
$response = new-object $connection.SendRequest($request)
就像我說的那樣,我對如何設置/發送證書和密鑰感到困惑。 我以為我可以做$connection.ClientCertificates = $path
,但該屬性是只讀的。 我還以為我必須用$System.Net.NetworkCredential
做一些事情,但我不確定證書和密鑰是否真的與用戶名和密碼相對應。 我提到了一個執行LDAP查詢並使用PKI的Perl腳本,您可以這樣做:
clientcert => '/path/to/cert.pem'
clientkey => '/path/to/key.pem'
Powershell的等價物是什么? 我是否必須對System.Security.Cryptography.X509Certificates.X509Certificate
做些什么?
任何幫助,將不勝感激!
$connection.ClientCertificates.Add($cert)
$cert
必須是X509Certificate
類,並從商店獲取證書
$allPersonalCerts = @( Get-ChildItem -Path 'Cert:\CurrentUser\my' )
它返回的數組X509Certificate
的對象(或X509Certificate2
其是用於子類X509Certificate
)
注意:在進行PowerShell編程時,您始終可以通過Google搜索C#或VB.net解決方案來搜索幫助。 這是.Net和面向.net的語言的例子在語法上有所不同
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.