gpt4 book ai didi

powershell - gpg with powershell - 密码安全

转载 作者:行者123 更新时间:2023-12-03 17:11:03 26 4
gpt4 key购买 nike

我正在使用 gnupg 通过 powershell 脚本加密和解密数据,问题是我在代码中有密码。这可能不是最好的解决方案。向脚本提供密码的最佳和安全方式是什么?谢谢。

C:\"Program Files"\GNU\GnuPG\gpg2.exe --passphrase mypassphrase --batch --output C:\Z\$decrypted_file.xls --decrypt C:\_Zo\$encrypted_file

最佳答案

您可以加密磁盘上的密码或密码。

以下解决方案使用计算机作为用户

以下两个脚本是 securot 框架 .NET 程序集。

对于服务器计算机,可以通过计算机身份来保护 secret 。此代码利用了这样一个事实,即任何可以在计算机上运行代码的人都可以访问密码。所以密码文件可以跨网络共享,只能由服务器自己解码。您可以将 ACL 添加到密码文件,以使其仅供某些用户组读取。

加密(必须在服务器计算机上完成):

# Mandatory Framework .NET Assembly 
Add-Type -assembly System.Security

# String to Crypt
$passwordASCII = Read-Host -Prompt "Entrer le mot de passe"

# String to INT Array
$enc = [system.text.encoding]::Unicode
$clearPWD_ByteArray = $enc.GetBytes( $passwordASCII.tochararray())

# Crypting
$secLevel = [System.Security.Cryptography.DataProtectionScope]::LocalMachine
$bakCryptedPWD_ByteArray = [System.Security.Cryptography.ProtectedData]::Protect($clearPWD_ByteArray, $null, $secLevel)

# Store in Base 64 form
$B64PWD_ByteArray = [Convert]::ToBase64String($bakCryptedPWD_ByteArray)
Set-Content -LiteralPath c:\Temp\pass.txt -Value $B64PWD_ByteArray

解码:

# Mandatory Framework .NET Assembly
Add-Type -assembly System.Security

# Getting from Base 64 storage
$resCryptedPWD_ByteArray = [Convert]::FromBase64String((Get-Content -LiteralPath c:\Temp\pass.txt))

# Decoding
$secLevel = [System.Security.Cryptography.DataProtectionScope]::LocalMachine
$clearPWD_ByteArray = [System.Security.Cryptography.ProtectedData]::Unprotect( $resCryptedPWD_ByteArray, $null, $secLevel )

# Dtring from int Array
$enc = [system.text.encoding]::Unicode
$enc.GetString($clearPWD_ByteArray)

关于powershell - gpg with powershell - 密码安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10173244/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com