Navigation

Documentation API

Intégrez facilement EarnGuardian dans vos projets pour protéger vos liens contre les bypasses Linkvertise

Qu'est-ce que EarnGuardian ?

EarnGuardian est un service de protection de liens qui empêche les utilisateurs de contourner les liens Linkvertise. Il utilise un chiffrement AES-256 avec RSA-OAEP pour sécuriser vos URLs de manière robuste.

Chiffrement AES-256 + RSA-OAEP
Protection anti-bypass avancée
Support Python et JavaScript
Implémentation simple

Installation

Prérequis Python

pip install cryptography

Nécessite Python 3.6+ et la bibliothèque cryptography pour le chiffrement

Implémentation

import json, base64, secrets
from urllib.parse import urlencode
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
from cryptography.hazmat.primitives import hashes, serialization
from cryptography.hazmat.primitives.asymmetric import padding
from cryptography.hazmat.backends import default_backend

# RSA Public Key for encryption
PEM_KEY = """-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsJdFWbKk6MY03IjsAtv3
hf8QqvFiQko6weaCtde5HkrAdXXt/N64mOAzhh8jhptWMjFLqFt6zzexB02n0qbb
cxP7uWMHZU4gcqI2dwP09DFX8iVpHhj3z35EVKtd94uSsbn/A2E54cjfgfit4VhP
m9NswEnXZmHhEey50n8VSZn1h8sDvY6vSLmO/Mio1CgqJ6+Pbf8gagnxprNr1xs+
i2yWh/CUfA+q3WoA/NmECLqJ4POPPWskjqzUfxjw+Ujs75owipY2csbPUjp1gRQn
2zi2Oay0NVjtnZGITW7ElvVuXVfVPp2Z7sa/t/bvMAQu7OHsgLF/PiHi3Rk0zasf
LwIDAQAB
-----END PUBLIC KEY-----"""

def earnguardian(url: str, user_id: int) -> str:
    # Validate input parameters
    if not isinstance(url, str):
        raise ValueError(f"Invalid 'url' parameter - expected: str, received: {type(url).__name__} ({url})")
    if not isinstance(user_id, int):
        raise ValueError(f"Invalid 'user_id' parameter - expected: int, received: {type(user_id).__name__} ({user_id})")
    
    def generate_aes_key():
        return secrets.token_bytes(16)  # 128-bit AES key
    
    def encrypt_with_aes(data: str, key: bytes):
        iv = secrets.token_bytes(16)
        cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=default_backend())
        encryptor = cipher.encryptor()
        
        # Convert to bytes and apply PKCS7 padding
        data_bytes = data.encode('utf-8')
        pad_length = 16 - (len(data_bytes) % 16)
        padded_data = data_bytes + bytes([pad_length] * pad_length)
        
        encrypted = encryptor.update(padded_data) + encryptor.finalize()
        return {
            'iv': base64.b64encode(iv).decode('utf-8'),
            'data': base64.b64encode(encrypted).decode('utf-8')
        }
    
    def encrypt_aes_key_with_rsa(aes_key: bytes):
        # Load RSA public key and encrypt AES key with RSA-OAEP
        rsa_key = serialization.load_pem_public_key(PEM_KEY.encode('utf-8'), backend=default_backend())
        encrypted = rsa_key.encrypt(aes_key, padding.OAEP(
            mgf=padding.MGF1(algorithm=hashes.SHA256()),
            algorithm=hashes.SHA256(), label=None))
        return base64.b64encode(encrypted).decode('utf-8')
    
    def process_url(input_url: str):
        url_string = str(input_url)
        
        # Validate URL format
        if not url_string or not (url_string.startswith('http://') or url_string.startswith('https://')):
            raise ValueError(f'Invalid URL - received: "{url_string}". Must start with http:// or https://')
        
        # Generate encryption keys and encrypt data
        aes_key = generate_aes_key()
        json_data = json.dumps({'url': url_string, 'userId': user_id}, separators=(',', ':'))
        encrypted_data = encrypt_with_aes(json_data, aes_key)
        encrypted_aes_key = encrypt_aes_key_with_rsa(aes_key)
        
        # Build secure URL with encrypted parameters
        params = [('data', encrypted_data['data']), ('iv', encrypted_data['iv']), ('key', encrypted_aes_key)]
        return f"https://votredomaine.com/verify?{urlencode(params)}"

    try:
        return process_url(url)
    except Exception as e:
        print(f"EarnGuardian - Error processing URL: {e}")
        raise

# Example usage
if __name__ == "__main__":
    url_to_secure = "https://google.com/"
    try:
        secured_url = earnguardian(url_to_secure, 1)
        print(f'Original URL: {url_to_secure}')
        print(f'Secured URL: {secured_url}')
    except Exception as error:
        print(f'Error during securing: {error}')

Paramètres de la fonction

ParamètreTypeDescriptionExemple
urlstringL'URL à protéger (doit commencer par http:// ou https://)"https://example.com/"
user_id / userIdintegerIdentifiant unique de l'utilisateur (nombre entier)123

Comment obtenir votre userId ?

Votre userId unique est disponible dans votre tableau de bord EarnGuardian. Connectez-vous à votre compte pour le récupérer.

Accéder au DashboardVotre userId se trouve dans la section "Informations du compte"

Valeur de retour

Succès

Retourne une URL sécurisée qui redirige vers notre service de vérification

https://votredomaine.com/verify?data=...&iv=...&key=...

Erreur

Lève une exception ValueError ou autre en cas d'erreur

Exemple d'usage

# Complete usage example with error handling
import sys

def secure_my_link(original_url, user_identifier):
    try:
        # Call EarnGuardian function
        protected_url = earnguardian(original_url, user_identifier)
        
        print(f"✅ Original URL: {original_url}")
        print(f"🔒 Protected URL: {protected_url}")
        
        # You can now use this protected URL
        # For example, send it via email or display it on your website
        return protected_url
        
    except ValueError as e:
        print(f"❌ Validation error: {e}")
        return None
    except Exception as e:
        print(f"❌ Unexpected error: {e}")
        return None

# Test with different cases
if __name__ == "__main__":
    # Valid case
    result = secure_my_link("https://download.example.com/file.zip", 123)
    
    # Error case - invalid URL
    result = secure_my_link("invalid-url", 123)
    
    # Error case - invalid user_id
    result = secure_my_link("https://example.com", "invalid_user_id")

Notes importantes

Sécurité

La clé publique RSA est intégrée dans le code. En production, assurez-vous que cette clé correspond à votre serveur EarnGuardian.

URL du service

L'URL de base "http://localhost:3000" doit être remplacée par votre domaine en production.

Compatibilité

Testé avec Python 3.7+ et cryptography 3.0+

Support et aide

Problèmes courants

Erreur de cryptographie : Vérifiez l'installation des dépendances

URL invalide : L'URL doit commencer par http:// ou https://

Web Crypto indisponible : Utilisez HTTPS en production

EarnGuardian - Anti-Bypass Linkvertise | Secure your profits