Newer
Older
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 hashlib
import datetime
from Errors import *
from RSA import encode_private
def sign(information, private_key):
result = hashlib.sha256(information.encode())
hash_value = result.digest()
signature = encode_private(private_key, hash_value)
return signature
class SignatureBasique:
def __init__(self, information, private, certificat, type_chiffrement="SHA256"):
print("Creation d'une signature")
now = datetime.datetime.now()
if certificat.get_date_fin_validite() < now:
print("Erreur : certificat expiré")
raise SignError("Erreur : certificat expiré")
CRL = certificat.get_prestataire().get_liste_revocation()
if certificat.get_ID() in CRL:
print("Erreur : certificat revoqué")
raise SignError("Erreur : certificat revoqué")
if type_chiffrement != "SHA256":
print("ATTENTION type de chiffrement " + type_chiffrement + " non supporté, utilisation de SHA256")
self.__type_chiffrement = type_chiffrement
self.__information = information
self.__valeur_signature = sign(information, private)
self.__certificat_ID = certificat.get_ID()
self.__heure_date = datetime.datetime.now()
def get_information(self):
return self.__information
def get_valeur_signature(self):
return self.__valeur_signature
def get_certificat_ID(self):
return self.__certificat_ID
def get_type(self):
return "signature basique"