-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
huy
committed
Apr 27, 2021
1 parent
2702fb2
commit c0832d8
Showing
4 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
# digital-signature-python | ||
# Digital Signature Python | ||
|
||
Argorithm: hmac-sha256 | ||
|
||
Run: ```python3 ./main/main.py``` | ||
|
||
Version: python3.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from util.digital_signature import DigitalSignature | ||
|
||
if __name__ == '__main__': | ||
signature1 = DigitalSignature(data='abc', | ||
secret='6a87c625-e186-43bc-8160-b6e80e1a910b').get_signature() | ||
|
||
signature2 = DigitalSignature(data='abc', | ||
secret='6a87c625-e186-43bc-8160-b6e80e1a910b').get_signature() | ||
|
||
print('{}\n{}'.format(signature1, signature2)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import hashlib | ||
import hmac | ||
|
||
|
||
class DigitalSignature: | ||
__data: bytes | ||
__secret: bytes | ||
__encode: str | ||
|
||
def __init__(self, | ||
data: str, | ||
secret: str, | ||
encode='utf-8'): | ||
self.__encode = encode | ||
self.__data = bytes(data, self.__encode) | ||
self.__secret = bytes(secret, self.__encode) | ||
|
||
def get_signature(self): | ||
signature = self.__calculate_hmac(secret=self.__secret, | ||
data=self.__data) | ||
|
||
return signature.hexdigest() | ||
|
||
@staticmethod | ||
def __calculate_hmac(secret: bytes, | ||
data: bytes, | ||
algorithm=hashlib.sha256): | ||
return hmac.new(secret, data, algorithm) |
Empty file.