File tree Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Expand file tree Collapse file tree 4 files changed +45
-1
lines changed Original file line number Diff line number Diff line change 1
- # digital-signature-python
1
+ # Digital Signature Python
2
+
3
+ Argorithm: hmac-sha256
4
+
5
+ Run: ``` python3 ./main/main.py ```
6
+
7
+ Version: python3.x
Original file line number Diff line number Diff line change
1
+ from util .digital_signature import DigitalSignature
2
+
3
+ if __name__ == '__main__' :
4
+ signature1 = DigitalSignature (data = 'abc' ,
5
+ secret = '6a87c625-e186-43bc-8160-b6e80e1a910b' ).get_signature ()
6
+
7
+ signature2 = DigitalSignature (data = 'abc' ,
8
+ secret = '6a87c625-e186-43bc-8160-b6e80e1a910b' ).get_signature ()
9
+
10
+ print ('{}\n {}' .format (signature1 , signature2 ))
Original file line number Diff line number Diff line change
1
+ import hashlib
2
+ import hmac
3
+
4
+
5
+ class DigitalSignature :
6
+ __data : bytes
7
+ __secret : bytes
8
+ __encode : str
9
+
10
+ def __init__ (self ,
11
+ data : str ,
12
+ secret : str ,
13
+ encode = 'utf-8' ):
14
+ self .__encode = encode
15
+ self .__data = bytes (data , self .__encode )
16
+ self .__secret = bytes (secret , self .__encode )
17
+
18
+ def get_signature (self ):
19
+ signature = self .__calculate_hmac (secret = self .__secret ,
20
+ data = self .__data )
21
+
22
+ return signature .hexdigest ()
23
+
24
+ @staticmethod
25
+ def __calculate_hmac (secret : bytes ,
26
+ data : bytes ,
27
+ algorithm = hashlib .sha256 ):
28
+ return hmac .new (secret , data , algorithm )
You can’t perform that action at this time.
0 commit comments