cobra_db.encrypt
Module Contents
Classes
Class to group all methods related to validating personal numbers. |
|
Hash method for the VAIB project, uses a sha512/256 hashing which is |
- class cobra_db.encrypt.PersonalNumberValidator[source]
Class to group all methods related to validating personal numbers. Checksum is calculated according to https://en.wikipedia.org/wiki/Personal_identity_number_(Sweden)#Checksum
- static get_checksum(personal_number: str) int [source]
Calculate the checksum for a personal number
- Parameters:
personal_number – 10 digit pnr. Without any other characters.
- static validate(personal_number: str) cobra_db.enums.PersonalNumberValidity [source]
Checks different aspects of validity described in the PnrValidity enum. It is important to store this information along with the hashed PersonalNumber to be able to debug matching problems later. This is because the hashed version of 19000101-1234, 190001011234 and 0001011234 are totally different. At least with this information we can try to modify one side or the other of the matching to fix it.
- class cobra_db.encrypt.Hasher(secret_salt: str)[source]
Hash method for the VAIB project, uses a sha512/256 hashing which is “a one way cryptographic process”, i.e. irreversible.
- hash(msg: str)[source]
Hash a message
- Parameters:
msg – message that we want to encrypt, normally the personnummer or the StudyID.
- Returns:
the encrypted message as hexdigest (in characters from ‘0’ to ‘9’ and ‘a’ to ‘f’)
- hash_personal_number(personal_number: str) Tuple[str, cobra_db.enums.PersonalNumberValidity] [source]
Hash the personnal number after removing all characters that are not 0-9, a-z, or A-Z. Obtain the validity of the personal number before the hashing.
- Parameters:
personal_number – personal number to be hashed
- Returns:
hashed string and validity of the pre-hashed pnr