vbscript 加密函数_VBScript的简单可逆加密

本文介绍了一种用于VBScript脚本的可逆加密方法,以模糊存储密码,提高安全性。作者提供了一个完整的加密和解密脚本,强调这并不适用于高度敏感信息的保护,但可以在日常场景中防止非技术用户轻易获取密码。
摘要由CSDN通过智能技术生成

vbscript 加密函数

It seems these days I’m writing a lot of VBScript scripts. My scripts are often interacting with a MySQL database but could be doing other things as well, such as connecting to workstations to push files. One of the biggest problems with scripts that need credentials is how to store the password in these clear text files. I’ve come up with a reversible encryption to store the password. The script below allows you to completely encrypt or decrypt a password using a custom key.

如今看来,我正在编写许多VBScript脚本。 我的脚本经常与MySQL数据库进行交互,但是也可以做其他事情,例如连接到工作站以推送文件。 需要凭据的脚本的最大问题之一是如何在这些明文文件中存储密码。 我想出了一种可逆的加密方式来存储密码。 下面的脚本使您可以使用自定义密钥完全加密或解密密码。

Now I fancy myself as security aware – I am not an IT Security professional. And this script is not intended as a truly secure method of storing passwords. Nor am I suggesting it is unbreakable or otherwise hard to decode without the key and encryption methodology below. It is ONLY meant to OBSCURE otherwise clear-text passwords in VBScripts. And obscurity is not security. Clear?

现在,我幻想自己具有安全意识–我不是IT安全专业人员。 而且该脚本并非旨在作为一种真正安全的密码存储方法。 如果没有下面的密钥和加密方法,我也不会暗示它是坚不可摧的,否则很难解码。 这仅是为了避免在VBScript中使用其他明文密码。 默默无闻不是安全。 明确?

On to the script…

进入脚本...

Option Explicit

Function GetParam(ParamNumber)    'Exclusive to VBS Scripts
    Dim GetParam_CmdArgs

    Set GetParam_CmdArgs = WScript.Arguments

    If GetParam_CmdArgs.Count = 3 Then
        GetParam = GetParam_CmdArgs(ParamNumber)
    ElseIf GetParam_CmdArgs.Count = 1 Then
        If UCase(Left(GetParam_CmdArgs(0), 1)) = "H" Then Help
    End If
End Function

Function ValidKey(Key)    'Ensures constants when computing character hexadecimal values don't exceed 255 (FF)
    Dim ValidKey_KeyParams    
    ValidKey_KeyParams = Split(Key, "-")    'Using "-" as a delimiter makes it impossible to have a negative number
    If UBound(ValidKey_KeyParams) <> 2 Then    'Wrong number of parameters in key
        ValidKey = False
    Else    'Max computed value is 127.
        If ValidKey_KeyParams(0) + (ValidKey_KeyParams(1) * ValidKey_KeyParams(2)) > 127 Then 
            ValidKey = False
        Else
            ValidKey = True
        End If
    End If
End Function

Function DecryptPassword(UseHash, Key)
    Dim DecryptPassword_KeyParams
    Dim DecryptPassword_PWChar
    Dim DecryptPassword_ChkChar
    Dim DecryptPassword_UseString
    Dim DecryptPassword_Count

    DecryptPassword_KeyParams = Split(Key, "-")

    DecryptPassword_UseString = UseHash
    DecryptPassword_Count = 0
    Do Until Len(DecryptPassword_UseString) < 3        '3 is minimum length of a character Char 1 = Salt 0, Char 2, 3 = Hex of Ascii code
        DecryptPassword_ChkChar = CInt(Left(DecryptPassword_UseString, 1))        'Start with the first character of the current version of the password string
        DecryptPassword_PWChar = (CInt(Clng("&h" & Mid(DecryptPassword_UseString, DecryptPassword_ChkChar + 2, 2)) - (DecryptPassword_KeyParams(0) + DecryptPassword_KeyParams(1) * DecryptPassword_ChkChar)))
        DecryptPassword = DecryptPassword & Chr(DecryptPassword_PWChar)
        DecryptPassword_UseString = Trim(Right(DecryptPassword_UseString, Len(DecryptPassword_UseString) - DecryptPassword_ChkChar - 3))
    Loop
End Function

Function RandomChar    'Generate a random hexadecimal value
    Randomize Timer
    RandomChar = Trim(Hex(Int(Rnd * 16)))
End Function

Function EncryptPassword(UsePassword, Key)
    Dim EncryptPassword_Character
    Dim EncryptPassword_SaltChars
    Dim EncryptPassword_KeyParams
    Dim EncryptPassword_Salt
    
  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值