Jump to content

Working with hashed/hidden passwords in a function


Recommended Posts

I fully understand the risks involved with using the following code, I simply want it to be able to store several of my own personal login passwords without being stored as plain text in the body of the script. For example, I have a very simple login script which just preforms a 

Send("password")

Send ({ENTER})

But I'd like to obfuscate the plain text password into something that is not so readily insecure. Hence, the below:

#include <Crypt.au3>
; Code provided by Robjong - Autoit
_Crypt_Startup()
Global $sPasswordCT = '0x3F10544A42DE8D16C2C590C20640A00D'
Global $sJoinDomainPassword = ''
$sJoinDomainPassword = _Decrypt("password", $sPasswordCT)
MsgBox(0,"Password","Admin password: " & $sJoinDomainPassword)
_Crypt_Shutdown()
Func _Decrypt($sKey, $sData)
    Local $hKey = _Crypt_DeriveKey($sKey, $CALG_AES_256)
    Local $sDecrypted = BinaryToString(_Crypt_DecryptData(Binary($sData), $hKey, $CALG_USERKEY))
    _Crypt_DestroyKey($hKey)
    Return $sDecrypted
EndFunc

 

Found this on the forums, but simply cannot find a way to change "secret" to any other text. The "0x3F10544A42DE8D16C2C590C20640A00D" is locked and I have no idea how to generate my own set of AES 256 hashes to correspond with the passwords I want to use. Ideally I'd have a dozen variables, each equaling one of my dozen passwords, but again I can't figure out a way to change "$sJoinDomainPassword"

PS I love the forums, very helpful and thanks in advance :)

Link to comment
Share on other sites

You need 2 scripts.  The first will generate the binary passwords.  The second (the one you have written) will use the encrypted password.

I have put the 2 scripts into a single one for simplicity.

#include <Crypt.au3>

_Crypt_Startup()

;script 1 (script to generate encrypt password)
Local $password = InputBox("Encryption", "Enter password")
If @error Then Exit
Local $result = _Encrypt("password", $password)
MsgBox($MB_SYSTEMMODAL, "", $result)
; ClipBoard now contains the binary password : paste it into your script or save it into a file or registry

;script 2 (script to use encrypted password)
Local $sPasswordCT = ClipGet() ; replace ClipGet with the binary string or read it from a file or registry
Local $sJoinDomainPassword = _Decrypt("password", $sPasswordCT)
MsgBox(0, "Password", "Admin password: " & $sJoinDomainPassword)

_Crypt_Shutdown()

Func _Decrypt($sKey, $sData)
  Local $hKey = _Crypt_DeriveKey($sKey, $CALG_AES_256)
  Local $sDecrypted = BinaryToString(_Crypt_DecryptData(Binary($sData), $hKey, $CALG_USERKEY))
  _Crypt_DestroyKey($hKey)
  Return $sDecrypted
EndFunc   ;==>_Decrypt

Func _Encrypt($sKey, $sData)
  Local $hKey = _Crypt_DeriveKey($sKey, $CALG_AES_256)
  Local $sEncrypted = _Crypt_EncryptData($sData, $hKey, $CALG_USERKEY)
  _Crypt_DestroyKey($hKey)
  ClipPut($sEncrypted)
  Return $sEncrypted
EndFunc   ;==>_Encrypt

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...