Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
ARC4 Encryption (ARCFOUR)
Demonstrates simple ARC4 encryption to match some simple test vectors published by Wikipedia. ARC4 is a fast stream cipher supporting key lengths from 8 to 2048 bits (i.e. from 1 to 256 bytes). It is not a block cipher, so there is no padding, no modes, and no initialization vector. <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <% set crypt = Server.CreateObject("Chilkat_9_5_0.Crypt2") success = crypt.UnlockComponent("Anything for 30-day trial") If (success <> 1) Then Response.Write Server.HtmlEncode("Crypt component unlock failed") & "<br>" End If ' Set the encryption algorithm to ARC4: crypt.CryptAlgorithm = "arc4" ' We want the encrypted output to be a hex-encoded string. crypt.EncodingMode = "hex" ' Encrypt some test vectors from Wikipedia: ' The key length (in bits) is equal to the number of us-ascii ' bytes in our key string * 8. ' ARC4( "Key", "Plaintext" ) == BBF316E8D940AF0AD3 crypt.KeyLength = 24 crypt.SetEncodedKey "Key","ascii" cipherText = crypt.EncryptStringENC("Plaintext") Response.Write Server.HtmlEncode(cipherText) & "<br>" plainText = crypt.DecryptStringENC(cipherText) Response.Write Server.HtmlEncode(plainText) & "<br>" ' ARC4( "Wiki", "pedia" ) == 1021BF0420 crypt.KeyLength = 32 crypt.SetEncodedKey "Wiki","ascii" cipherText = crypt.EncryptStringENC("pedia") Response.Write Server.HtmlEncode(cipherText) & "<br>" plainText = crypt.DecryptStringENC(cipherText) Response.Write Server.HtmlEncode(plainText) & "<br>" ' ARC4( "Secret", "Attack at dawn" ) == 45A01F645FC35B383552544B9BF5 crypt.KeyLength = 48 crypt.SetEncodedKey "Secret","ascii" cipherText = crypt.EncryptStringENC("Attack at dawn") Response.Write Server.HtmlEncode(cipherText) & "<br>" plainText = crypt.DecryptStringENC(cipherText) Response.Write Server.HtmlEncode(plainText) & "<br>" ' Note: The call to SetEncodedKey serves to set the key ' to the us-ascii bytes of the string. %> </body> </html> |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.