4
4
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
5
6
6
from argparse import ArgumentParser
7
- from base64 import urlsafe_b64encode
8
7
from getpass import getpass
9
- from os import urandom
10
-
8
+ from secrets import token_hex , token_urlsafe
11
9
import hmac
12
10
13
11
def generate_salt (size ):
14
12
"""Create size byte hex salt"""
15
- return urandom (size ). hex ( )
13
+ return token_hex (size )
16
14
17
15
def generate_password ():
18
16
"""Create 32 byte b64 password"""
19
- return urlsafe_b64encode ( urandom ( 32 )). decode ( 'utf-8' )
17
+ return token_urlsafe ( 32 )
20
18
21
19
def password_to_hmac (salt , password ):
22
- m = hmac .new (bytearray ( salt , 'utf-8' ), bytearray ( password , 'utf-8' ), 'SHA256' )
20
+ m = hmac .new (salt . encode ( 'utf-8' ), password . encode ( 'utf-8' ), 'SHA256' )
23
21
return m .hexdigest ()
24
22
25
23
def main ():
@@ -38,8 +36,8 @@ def main():
38
36
password_hmac = password_to_hmac (salt , args .password )
39
37
40
38
print ('String to be appended to bitcoin.conf:' )
41
- print ('rpcauth={0 }:{1 }${2}' . format ( args . username , salt , password_hmac ) )
42
- print ('Your password:\n {0}' . format ( args .password ) )
39
+ print (f 'rpcauth={ args . username } :{ salt } ${ password_hmac } ' )
40
+ print (f 'Your password:\n { args .password } ' )
43
41
44
42
if __name__ == '__main__' :
45
43
main ()
0 commit comments