Powershell实现加密解密文本文件方法实例(powershell帮助文档)新鲜出炉

随心笔谈2年前发布 admin
194 0 0

文章摘要

该文章介绍了一段使用PowerShell脚本的代码,用于在Windows 10环境中解密敏感文件。代码通过读取用户的密码并生成密钥,对存储在`tempsecret.txt`文件中的秘密文本进行解密。如果密钥正确,会提取文件中的内容;如果密钥错误,则显示错误信息。该脚本展示了通过自动化工具对敏感文件进行解密的过程,并强调了在数据保护中的重要性。


$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”

© 版权声明

相关文章