SQL Server
SQL Server
WPA Key Calculation from PassPhrase to Hex
See more Encryption Examples
Demonstrates how to calculate a WPA key from a passprhase and network SSID.Chilkat SQL Server Downloads
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls.
--
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
DECLARE @crypt int
EXEC @hr = sp_OACreate 'Chilkat.Crypt2', @crypt OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @wpaHexKey nvarchar(4000)
-- The "ps" is the WPA passphrase
DECLARE @pw nvarchar(4000)
SELECT @pw = 'password'
DECLARE @pwCharset nvarchar(4000)
SELECT @pwCharset = 'ansi'
-- Hash algorithms may be: sha1, md2, md5, etc.
DECLARE @hashAlg nvarchar(4000)
SELECT @hashAlg = 'sha1'
-- Specify the SSID in hex:
-- For example, if the SSID is "ABC", then the
-- hex values for these us-ascii chars is "414243"
DECLARE @ssidHex nvarchar(4000)
SELECT @ssidHex = '414243'
-- The WPA key calculation will always use 4096 iterations.
DECLARE @iterationCount int
SELECT @iterationCount = 4096
-- The WPA hex output should be 256 bits.
DECLARE @outputBitLen int
SELECT @outputBitLen = 256
-- Indicate that "hex" is to be returned.
DECLARE @enc nvarchar(4000)
SELECT @enc = 'hex'
EXEC sp_OAMethod @crypt, 'Pbkdf2', @wpaHexKey OUT, @pw, @pwCharset, @hashAlg, @ssidHex, @iterationCount, @outputBitLen, @enc
PRINT @wpaHexKey
EXEC @hr = sp_OADestroy @crypt
END
GO