WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Password Tips

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Encrypt Password and Store in Binary Registry key

 Keywords: Encrypt Decrypt Password string Binary Registry RegSetBin RegQueryBin 

; Encrypt Password and Store in Binary Registry key

;The following code is not high security but is does stop the average user.

#DefineFunction EncryptStr( pwd )
   ;*******************************
   ; Encrypt Password
   ;*******************************
   b = StrLen( pwd )
   aa = b : "@" : pwd
   b = StrLen(aa)
   aa = aa : "JKHJY&GY&RTFUI&YGRDRDTYY*()&*(&*GYGGYR"
   aa = StrFix( aa, "&GG&^R^$", b )
   np = ""
   For x=1 To b
      xx = Char2Num( StrSub( aa, x, 1 ) )
      xx = xx + 125
      np = np : " " : ChrStringToHex(Num2Char(xx))
   Next
   pwd =  np
   Return pwd
#EndFunction

#DefineFunction DecryptStr( pwd )
   ;*******************************
   ; Decrypt Password
   ;*******************************
   np = StrReplace( pwd, " ", "" )
   np = ChrHexToString( np )
   b = StrLen( np )
   orig=""
   For x=1 To b
      xx = Char2Num( StrSub( np, x, 1 ) )
      If xx == 32 Then Continue
      xx = xx-125
      orig = orig : Num2Char(xx)
   Next
   s1 = ItemExtract( 1, orig, "@" )
   pwd = StrSub( orig, StrLen( s1 ) + 2, -1 )
   Return pwd
#EndFunction

;*******************************
; Test
;*******************************
pswd = '527532'
pswd = 'abcdefghijklmnopqrstuvwxyz0123456789'
subkeystring = 'SOFTWARE\Wilson WindowWare\Test'


; Create Registry key
RegCreateKey( @REGMACHINE, subkeystring )

encrypted_pswd = EncryptStr( pswd )
Pause( 'Encrypted password', encrypted_pswd )

; Set Binary value in registry
RegSetBin( @REGMACHINE, subkeystring, encrypted_pswd )

; Read Binary value from registry
encrypted_pswd = RegQueryBin( @REGMACHINE, subkeystring )

; Decrypt value read from registry
decrypted_pswd = DecryptStr( encrypted_pswd )
Pause( 'Decrypted password', decrypted_pswd )

response = AskYesNo( "Delete Registry Key?", "Do you want to delete the registry key?" )
If response == @YES
     RegDeleteKey( @REGMACHINE, subkeystring  )
EndIf

Exit

Article ID:   W18220
Filename:   Encrypt Password and Store in Binary Registry key.txt
File Created: 2011:03:11:12:36:56
Last Updated: 2011:03:11:12:36:56