44# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
66from argparse import ArgumentParser
7- from base64 import urlsafe_b64encode
87from getpass import getpass
9- from os import urandom
10-
8+ from secrets import token_hex , token_urlsafe
119import hmac
1210
1311def generate_salt (size ):
1412 """Create size byte hex salt"""
15- return urandom (size ). hex ( )
13+ return token_hex (size )
1614
1715def generate_password ():
1816 """Create 32 byte b64 password"""
19- return urlsafe_b64encode ( urandom ( 32 )). decode ( 'utf-8' )
17+ return token_urlsafe ( 32 )
2018
2119def 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' )
2321 return m .hexdigest ()
2422
2523def main ():
@@ -38,8 +36,8 @@ def main():
3836 password_hmac = password_to_hmac (salt , args .password )
3937
4038 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 } ' )
4341
4442if __name__ == '__main__' :
4543 main ()
0 commit comments