Problem solve Get help with specific problems with your technologies, process and projects.

Encryption in VBScript

This VBScript tip presents a Web-cookie encryption function.

Reader John Walker reprises his earlier encryption tip with one that will work in VBScript, as well as Visual Basic.

Back in October 2000 you were kind enough to publish a little encryption function of mine (thanks for the shirt) which was pretty much duplicated here a few weeks ago.

I just had the need for some Web-cookie encryption and discovered that neither of those encryption tips will work in VBScript due to the language's inexplicable lack of support for the Mid Statement.

This revised function will work in VBScript. To encrypt put the text to be encrypted into the Text parameter and a string key in the Key parameter. To decrypt do the same thing in reverse.

 <% Function CryptVBS(Text, Key) KeyLen = Len(Key) For i = 1 To Len(Text) KeyPtr = (KeyPtr + 1) Mod KeyLen sTxtChr = Mid(Text, i, 1) wTxtChr = Asc(stxtchr) wKeyChr = Asc(Mid(Key, KeyPtr + 1, 1)) CryptKey = Chr(wTxtChr Xor wKeyChr) hold = hold & CryptKey Next CryptVBS = hold End Function %>

Thanks, John. No fair getting a second shirt, but we appreciate your updating this encryption function.

Did you like this tip? Why not let us know? Email to sound off, or visit our tips page to rate this, and other tips.

Related Book

VBScript Pocket Reference
Author : Matt Childs, Ron Petrusha and Paul Lomax
Publisher : O'Reilly & Associates
Published : Jan 2001
Summary : 
Microsoft's Visual Basic Scripting Edition (VBScript), a subset of Visual Basic for Applications, is a powerful language for Internet application development, where it can serve as a scripting language for server-side, client-side, and system scripting. Whether you're developing code for Active Server Pages, client-side scripts for Internet Explorer, code for Outlook forms, or scripts for Windows Script Host, VBScript Pocket Reference will be your constant companion.

Dig Deeper on .NET Framework security best practices

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.