Шифрование номера карты
RSA ключи для шифрования номера по слоям (действительны до мая 2029)
Python
Нужен пакет cryptography.
import base64
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding
def rsa_encrypt(message: str, public_key: bytes) -> str:
"""Шифрование с использованием OAEP RSA"""
message = message.replace(" ", "")
if len(message) not in range(13, 20) or not message.isdigit():
raise Exception("Card number must contain 13 to 19 decimal characters only")
message = message.encode()
public_key = serialization.load_pem_public_key(public_key)
_padding = padding.OAEP(
mgf=padding.MGF1(algorithm=hashes.SHA1()),
algorithm=hashes.SHA1(),
label=None,
)
encrypt = public_key.encrypt(message, padding=_padding)
return base64.b64encode(encrypt).decode()