[#2] Add methods sign and verify
Signed-off-by: ilyas585 <niyazov2023@gmail.com>
This commit is contained in:
parent
4433fc425a
commit
a51ef880fe
9 changed files with 225 additions and 15 deletions
24
frostfs_api/cryptography/signer.py
Normal file
24
frostfs_api/cryptography/signer.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
import ecdsa
|
||||
from hashlib import sha256, sha512
|
||||
|
||||
|
||||
class Signer:
|
||||
def sign_rfc6979(self, private_key: bytes, message: bytes) -> bytes:
|
||||
if len(private_key) == 0 or private_key is None:
|
||||
raise ValueError(f"Incorrect private_key: {private_key}")
|
||||
|
||||
sk = ecdsa.SigningKey.from_string(private_key, curve=ecdsa.NIST256p, hashfunc=sha256)
|
||||
|
||||
signature = sk.sign_deterministic(message)
|
||||
|
||||
return signature
|
||||
|
||||
def sign(self, private_key: bytes, message: bytes) -> bytes:
|
||||
if len(private_key) == 0 or private_key is None:
|
||||
raise ValueError(f"Incorrect private key: {private_key}")
|
||||
|
||||
sk = ecdsa.SigningKey.from_string(private_key, curve=ecdsa.NIST256p, hashfunc=sha512)
|
||||
|
||||
signature = sk.sign(message)
|
||||
|
||||
return signature
|
Loading…
Add table
Add a link
Reference in a new issue