File size: 1,227 Bytes
39a9e4f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70bb488
39a9e4f
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sys, time
import base64
def printError(msg=''):
    if msg != "":
        print("Error: " + msg)
    print('Usage: ')
    print(sys.argv[0] + " [private key file] [consumer ID] [Key version]")
    print('')
    print('Example: ')
    print(sys.argv[0] + " private_key.pem 44444444-23f9-3333-2222-111111111111 1")
    print('')
    print('')
    sys.exit()

def sign_data(private_key, data):
    from Crypto.PublicKey import RSA 
    from Crypto.Signature import PKCS1_v1_5 
    from Crypto.Hash import SHA256 
    from base64 import b64encode, b64decode 
    key = open(private_key, "r") 
    rsakey = RSA.importKey(key.read()) 
    signer = PKCS1_v1_5.new(rsakey) 
    digest = SHA256.new()
    digest.update(data.encode('utf-8')) 
    sign = signer.sign(digest) 
    return b64encode(sign)

def main(argv):
    global logData
    global hostname
    try:

        
        privateKey ='untitled1.txt'


    except:
        printError()
    epoch_time = int(time.time()) * 1000
    data = 'd23d5ad5-b016-4a76-b6bb-c6bae0372374' + '\n' + str(epoch_time) + '\n' + '1' + '\n'
    print('Timestamp:', epoch_time)
    print('Signature:' , sign_data(privateKey, data).decode())

if __name__ == "__main__":
    main(sys.argv)