📗SpiderCrypt SDK Documentation

Description

Welcome . In this doc you gonna learn how to use SpiderCrypt SDK for data security. It provides robust functionalities for encryption, decryption, hashing, signing, and verifying data, using shared authentication keys and user identifiers to ensure traceability and security.


Classes and Methods

Class SpiderCrypt

This class is the core of the SpiderCrypt SDK and enables all the main cryptographic operations.

Initialization

SpiderCrypt(secret_key: str)
  • Parameter:

    • secret_key: Shared secret key used to initialize the class. It is required for all secure operations.


Main Methods

encrypt

encrypt(data: str, auth_key: str, user_id: str) -> bytes
  • Description: Encrypts sensitive data.

  • Parameters:

    • data: Data to encrypt (string).

    • auth_key: Authentication key used for this operation.

    • user_id: Identifier of the user performing the operation.

  • Returns: Encrypted data as bytes.


decrypt

decrypt(encrypted_data: bytes, auth_key: str, user_id: str) -> str
  • Description: Decrypts previously encrypted data.

  • Parameters:

    • encrypted_data: Encrypted data (as bytes).

    • auth_key: Authentication key used for this operation.

    • user_id: Identifier of the user performing the operation.

  • Returns: Decrypted data as a string.


hash_data

hash_data(data: str, auth_key: str, user_id: str) -> bytes
  • Description: Creates a unique hash of the data to ensure its integrity.

  • Parameters:

    • data: Data to hash (string).

    • auth_key: Authentication key used for this operation.

    • user_id: Identifier of the user performing the operation.

  • Returns: Hashed value as bytes.


sign_data

sign_data(data: str, auth_key: str, user_id: str) -> bytes
  • Description: Generates a digital signature of the data to ensure its authenticity.

  • Parameters:

    • data: Data to sign (string).

    • auth_key: Authentication key used for this operation.

    • user_id: Identifier of the user performing the operation.

  • Returns: Signature of the data as bytes.


verify_signature

verify_signature(data: str, signature: bytes, auth_key: str, user_id: str) -> bool
  • Description: Verifies if the signature of the data is valid.

  • Parameters:

    • data: Original data (string).

    • signature: Signature to verify (as bytes).

    • auth_key: Authentication key used for this operation.

    • user_id: Identifier of the user performing the operation.

  • Returns: A boolean indicating if the signature is valid (True) or not (False).


Error Handling

PermissionError

Raised when authentication fails (e.g., if auth_key is incorrect).

Exception

Raised for any other non-specific errors (e.g., corrupted data or invalid format).


Example Usage

Here is a complete example of using the main features of the API:

from spidercrypt import SpiderCrypt  # Import the SpiderCrypt library

def main():
    # Shared authentication key for security
    auth_key = "d7kTW+Hz67I9B8F8NenqqbgDSd11HSFyT3D5Zt5GkK0="  # Secure secret key

    # Initialize SpiderCrypt with the secret key for secure operations
    cipher = SpiderCrypt(secret_key=auth_key)

    # Example data to secure
    data = "Sensitive data to secure."  # Your data to protect
    user_id = "user001"  # User identifier for tracking actions

    try:
        # Encrypt the data
        encrypted_data = cipher.encrypt(data, auth_key, user_id)
        print(f"Encrypted data: {encrypted_data.decode()}")

        # Decrypt the data
        decrypted_data = cipher.decrypt(encrypted_data, auth_key, user_id)
        print(f"Decrypted data: {decrypted_data}")

        # Hash the data (to ensure integrity)
        hashed_data = cipher.hash_data(data, auth_key, user_id)
        print(f"Hashed data: {hashed_data.hex()}")

        # Sign the data to ensure authenticity
        signature = cipher.sign_data(data, auth_key, user_id)
        print(f"Data signature: {signature.hex()}")

        # Verify the signature to ensure integrity
        is_valid = cipher.verify_signature(data, signature, auth_key, user_id)
        print(f"Signature valid: {is_valid}")

    except PermissionError as e:
        print(f"Authentication error: {e}")
    except Exception as e:
        print(f"An error occurred: {e}")

if __name__ == "__main__":
    main()

Additional Notes

  • Ensure the auth_key remains strictly confidential.

  • Trace operations by user (user_id) for better security management and audits.

  • Test all operations before deploying them in a production environment.

Here some SDK :

Python

pip install spidercrypt

Java

Make sure to have the SpiderCrypt library as a .jar file and add it to your project.

Ruby

gem install spidercrypt

Go

Use the Go package manager to import spidercrypt.

go get github.com/spidercrypt/spidercrypt

C#

Add the SpiderCrypt reference via NuGet or the .dll file.


3. Usage Examples

Python

import spidercrypt

# Hashing
data = "Sensitive data"
hashed_data = spidercrypt.hash_data(data)
print(f"Hashed: {hashed_data}")

# Signing
signature = spidercrypt.sign_data(data)
print(f"Signature: {signature}")

# Signature verification
is_verified = spidercrypt.verify_signature(data, signature)
print(f"Signature verified: {is_verified}")

# Encryption
encrypted_data = spidercrypt.encrypt(data)
print(f"Encrypted data: {encrypted_data['encrypted_data']}")
print(f"IV: {encrypted_data['iv']}")

# Decryption
decrypted_data = spidercrypt.decrypt(encrypted_data['encrypted_data'], encrypted_data['iv'])
print(f"Decrypted data: {decrypted_data}")

# Data Masking
masked_data = spidercrypt.mask_data(data)
print(f"Masked data: {masked_data}")

# Sensitive data detection
if spidercrypt.detect_sensitive_data(data):
    print("Sensitive data detected!")
else:
    print("No sensitive data detected.")

Java

import SpiderCrypt.Spidercrypt;

public class Main {
    public static void main(String[] args) {
        try {
            String data = "some sensitive data";
            String hashedData = Spidercrypt.hashData(data);
            System.out.println("Hashed: " + hashedData);

            String signature = Spidercrypt.signData(data);
            System.out.println("Signature: " + signature);

            boolean isSignatureValid = Spidercrypt.verifySignature(data, signature);
            System.out.println("Signature valid: " + isSignatureValid);

            Map<String, String> encryptedData = Spidercrypt.encrypt(data);
            System.out.println("Encrypted data: " + encryptedData.get("encrypted_data"));
            System.out.println("IV: " + encryptedData.get("iv"));

            String decryptedData = Spidercrypt.decrypt(encryptedData.get("encrypted_data"), encryptedData.get("iv"));
            System.out.println("Decrypted data: " + decryptedData);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Ruby

require 'spidercrypt'

data = "Sensitive data for test"

# Hashing
hashed_data = SpiderCrypt.hash_data(data)
puts "Hashed: #{hashed_data}"

# Signing
signature = SpiderCrypt.sign_data(data)
puts "Signature: #{signature}"

# Signature verification
is_verified = SpiderCrypt.verify_signature(data, signature)
puts "Signature verified: #{is_verified}"

# Encryption
encrypted_data = SpiderCrypt.encrypt(data)
puts "Encrypted data: #{encrypted_data[:encrypted_data]}"
puts "IV: #{encrypted_data[:iv]}"

# Decryption
decrypted_data = SpiderCrypt.decrypt(encrypted_data[:encrypted_data], encrypted_data[:iv])
puts "Decrypted data: #{decrypted_data.force_encoding('UTF-8')}"

# Data Masking
masked_data = SpiderCrypt.mask_data(data)
puts "Masked data: #{masked_data}"

# Sensitive data detection
if SpiderCrypt.detect_sensitive_data(data)
  puts "Sensitive data detected!"
else
  puts "No sensitive data detected."
end

Go

package main

import (
	"fmt"
	"spidercrypt"
)

func main() {
	cipher := spidercrypt.NewSpiderCrypt("0123456789abcdef")

	// Hashing
	data := "Sensitive data"
	hash := cipher.Hash(data)
	fmt.Println("Hashed:", hash)

	// Signing
	signature, err := cipher.Sign(data)
	if err != nil {
		fmt.Println("Error during signing:", err)
		return
	}
	fmt.Println("Signature:", signature)

	// Encryption
	encryptedData, err := cipher.Encrypt(data)
	if err != nil {
		fmt.Println("Error during encryption:", err)
		return
	}
	fmt.Println("Encrypted data:", encryptedData)

	// Decryption
	decryptedData, err := cipher.Decrypt(encryptedData)
	if err != nil {
		fmt.Println("Error during decryption:", err)
		return
	}
	fmt.Println("Decrypted data:", decryptedData)

	// Sensitive data detection
	if cipher.DLPCheck(data) {
		fmt.Println("DLP Alert: Sensitive data detected.")
	} else {
		fmt.Println("No sensitive data detected.")
	}
}

C#

using System;

public class Program
{
    static void Main(string[] args)
    {
        var spiderCrypt = new SpiderCrypt();
        string sensitiveData = "1234-5678-9876"; // Example of sensitive data

        // Hashing
        string hash = spiderCrypt.HashData(sensitiveData);
        Console.WriteLine($"Hashed: {hash}");

        // Signing
        string signature = spiderCrypt.SignData(sensitiveData);
        Console.WriteLine($"Signature: {signature}");

        // Signature verification
        bool isVerified = spiderCrypt.VerifySignature(sensitiveData, signature);
        Console.WriteLine($"Signature verified: {isVerified}");

        // Encryption
        string encryptedData = spiderCrypt.Encrypt(sensitiveData);
        Console.WriteLine($"Encrypted data: {encryptedData}");

        // Decryption
        string decryptedData = spiderCrypt.Decrypt(encryptedData);
        Console.WriteLine($"Decrypted data: {decryptedData}");

        // Data Masking
        string maskedData = spiderCrypt.MaskSensitiveData(sensitiveData);
        Console.WriteLine($"Masked data: {maskedData}");

        // Sensitive data detection
        bool isSensitive = spiderCrypt.DetectSensitiveData(sensitiveData);
        Console.WriteLine($"Sensitive data detected: {isSensitive}");
    }
}

PHP


<?php

require_once __DIR__ . '/vendor/autoload.php';

use Spidercrypt\DataProtection\Encryption\EncryptionManager;
use Spidercrypt\DataProtection\Masking\MaskingManager;
use Spidercrypt\DataProtection\Hashing\HashingManager;
use Spidercrypt\DataProtection\Tokenization\TokenizationManager;
use Spidercrypt\DataProtection\DLP\DlpManager;
use Spidercrypt\DataProtection\Decryption\DecryptionManager;
use Spidercrypt\DataProtection\Helpers\CryptoHelper;

// Création des objets pour chaque fonctionnalité
$encryptionManager = new EncryptionManager();
$maskedData = (new MaskingManager())->maskData('1234567890');
$hashedData = (new HashingManager())->hashData('password');
$tokenizedData = (new TokenizationManager())->tokenizeData('secure-data');
$dlpManager = new DlpManager();

// Encryptage de données
$encryptedData = $encryptionManager->encryptData('SensitiveData123');

// Décryptage de données
$decryptionManager = new DecryptionManager($encryptionManager->getKey(), $encryptionManager->getIv());
$decryptedData = $decryptionManager->decryptData($encryptedData);

// Affichage des résultats
echo "Encrypted: " . $encryptedData . PHP_EOL;
echo "Decrypted: " . $decryptedData . PHP_EOL;
echo "Masked: " . $maskedData . PHP_EOL;
echo "Hashed: " . $hashedData . PHP_EOL;
echo "Tokenized: " . $tokenizedData . PHP_EOL;
echo $dlpManager->preventDataLoss('Sensitive Information') . PHP_EOL;

Last updated