第一種 (Password 明碼)
Set-StrictMode -Version Latest
[string] $strPW = 'password'
[string] $strPFX = 'C:\Cert\www.contoso.com.pfx'
$cert = New-Object System.Security.Cryptography.X509Certificates.X509Certificate2
$cert.Import($strPFX,$strPW,[System.Security.Cryptography.X509Certificates.X509KeyStorageFlags]"DefaultKeySet")
$cert.Thumbprint
第二種 (Password 加密)
$PassWord = ConvertTo-SecureString -String 'password' -AsPlainText -Force
$Encrypted = ConvertFrom-SecureString -SecureString $Password
$Encrypted | Set-Content Encrypted.txt
$Secure2 = Get-Content Encrypted.txt | ConvertTo-SecureString
$mypfx = Get-PfxData -FilePath 'C:\Cert\www.contoso.com.pfx' -Password $Secure2
$mypfx.EndEntityCertificates.Thumbprint
第三種 (Password 加密)
$Secure = Read-Host -AsSecureString
$Encrypted = ConvertFrom-SecureString -SecureString $Secure -Key (1..16)
$Encrypted | Set-Content Encrypted.txt
$Secure2 = Get-Content Encrypted.txt | ConvertTo-SecureString -Key (1..16)
$mypfx = Get-PfxData -FilePath 'C:\Cert\www.contoso.com.pfx' -Password $Secure2
$mypfx.EndEntityCertificates.Thumbprint
沒有留言:
張貼留言