T
T
timur1022018-04-12 19:11:18
Python
timur102, 2018-04-12 19:11:18

How to generate psk key?

I need to generate a psk key. It can be generated with the wpa_passphrase "ssid" "passwd" command.
But do I need to do it in python ?

import os
import sys
import re
from subprocess import Popen, PIPE
ssid = sys.argv[1]
passwd= sys.argv[2]
command = """ wpa_passphrase "%s" "%s" """ % (ssid , passwd)
proc = Popen(
        command,
        shell = True,
        stdout=PIPE,stderr = PIPE
)
proc.wait()
res = proc.communicate()
result = res[0]
psk = re.findall("[a-f0-9]"*64,result)[0]
print(psk)

how can i get this psk easily?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
chupasaurus, 2018-04-12
@timur102

PSK = PBKDF2 (HMAC-SHA1, passwd, ssid, 4096, 256)
PBKDF2 appeared in the hashlib library since version 3.4, for it:

psk = hashlib.pbkdf2_hmac('sha1', passwd, ssid, 4096, 256)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question