wpa_passphrase "testing" "testingpassword"network={
ssid="testing"
#psk="testingpassword"
psk=ae9400eac47807861c32f6b2d52434594fe1f1cbbd5ae0d89d5199ea5e4c79aa
}
我做了一个Python脚本,因为这篇维基百科文章告诉我如何计算wpa psk:
像这样:
import hashlib, binascii
def wpa_psk(ssid, password):
dk = hashlib.pbkdf2_hmac('sha1', str.encode(password), str.encode(ssid), 4096)
return (binascii.hexlify(dk))
print((wpa_psk("testing", "testingpassword")))
输出:
b'ae9400eac47807861c32f6b2d52434594fe1f1cb'
这是由
wpa_passphrase
工具生成的 psk 的一部分。缺少什么?
现在可能为时已晚,我遇到了这个问题,你可以这样做:
import hashlib, binascii
def wpa_psk(ssid, password):
dk = hashlib.pbkdf2_hmac(
'sha1',
str.encode(password),
str.encode(ssid),
4096,
256
)
return (binascii.hexlify(dk))
print((wpa_psk('testing', 'testingPassword')[0:64].decode('utf8')))
输出是
131e1e221f6e06e3911a2d11ff2fac9182665c004de85300f9cac208a6a80531
你可以将其制作成脚本:
import hashlib, binascii
from getpass import getpass
def wpa_psk():
'''
Encrypt password using ssid and password for WPA and WPA2
'''
ssid=input("SSID: ")
dk = hashlib.pbkdf2_hmac(
'sha1', str.encode(getpass("Password: ")),
str.encode(ssid), 4096, 32
)
print(binascii.hexlify(dk).decode("UTF-8"))
唯一缺少的是在调用 hashlib.pbkdf2_hmac() 时指定 dklen 参数。该参数应设置为 32。
import hashlib, binascii
def wpa_psk(ssid, password):
dk = hashlib.pbkdf2_hmac('sha1', str.encode(password), str.encode(ssid), 4096, 32)
return (binascii.hexlify(dk))
print((wpa_psk("testing", "testingpassword")))