亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Powershell實現(xiàn)加密解密文本文件方法實例

 更新時間:2015年04月11日 09:28:53   投稿:junjie  
這篇文章主要介紹了Powershell實現(xiàn)加密解密文本文件方法實例,本文直接給出加密和解密代碼實例,需要的朋友可以參考下

適用于Powershell3.0及以后版本。
假設(shè)你需要給文件加密,下面教你如何給自己的文件加密:

$Path = "$env:temp\secret.txt"
$Secret = 'Hello World!'
$Passphrase = 'Some secret key'
 
$key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
 
$Secret |
 ConvertTo-SecureString -AsPlainText -Force |
 ConvertFrom-SecureString -Key $key |
 Out-File -FilePath $Path
 
notepad $Path

當(dāng)你需要解密出里面的內(nèi)容,這時就需要最初的密碼:

$Passphrase = Read-Host 'Enter the secret pass phrase'
 
$Path = "$env:temp\secret.txt"
 
$key = [Byte[]]($Passphrase.PadRight(24).Substring(0,24).ToCharArray())
 
try
{
 $decryptedTextSecureString = Get-Content -Path $Path -Raw |
 ConvertTo-SecureString -Key $key -ErrorAction Stop
 
 $cred = New-Object -TypeName System.Management.Automation.PSCredential('dummy', $decryptedTextSecureString)
 $decryptedText = $cred.GetNetworkCredential().Password
}
catch
{
 $decryptedText = '(wrong key)'
}
"The decrypted secret text: $decryptedText"

相關(guān)文章

最新評論