About


CastleFile is not just another file encryption website—it’s a completely new approach to file security. Traditional encryption methods rely on static passwords or randomly generated keys. CastleFile transforms this paradigm by using chess moves as an essential component of the encryption process. Your moves become the key to securing your files, making the encryption process both unique and highly personalized.

CastleFile is a revolutionary platform that brings together the art of chess and cutting-edge encryption technologies to ensure the highest level of security for your files. Designed for individuals and businesses who prioritize privacy and innovation, CastleFile combines your unique chess moves with AES encryption to create an unparalleled data protection system. This page provides an in-depth look at CastleFile, its features, best practices, limitations, and technical details.

Every interaction on CastleFile is driven by the following core values:

Features


1. Chess Move Integration

2. AES Encryption

3. Security and Privacy

4. Unique and Different

Best Practices


1. Save Your Chess Move Sequence

Always securely store the sequence of moves you use for encryption. Without it, decryption will not be possible.

2. Use Complex Chess Strategies

Play more than the minimum 4 moves to enhance the complexity of the encryption key. The more moves you play, the harder it becomes to break the encryption.

3. Verify File Integrity

After encryption, download the file and verify its integrity to ensure the process was successful.

4. Use Updated Browsers

Ensure you are using the latest version of your browser for compatibility and security.

Limitations


1. Dependency on Chess Moves

The decryption process requires the exact same chess move sequence as used during encryption. If you lose the sequence, the file cannot be decrypted.

2. Browser Compatibility

Certain features may not work optimally on outdated or unsupported browsers. Mobile users may experience issues with repeated downloads if the browser’s cache is not cleared.

3. File Size Limitations

Currently, CastleFile supports files up to a certain size limit to ensure faster processing and optimal performance.

4. No Recovery Option

For security reasons, CastleFile does not store encryption keys or files. If the chess move sequence is lost, recovery is impossible.

Technical Details


1. File Upload: The user uploads a file.

When the user uploads a file on the CastleFile platform, the process initiates the encryption and decryption workflow.
  • File Selection: The user selects the file they want to encrypt or decrypt from their device using the website's upload interface.
  • This step serves as the starting point for the encryption process, where the user's file will later be secured using the unique cryptographic key derived from their chess moves.

    2. User Plays Chess Moves: They're captured and converted into Encryption Key.

    This function combines chess moves from both the user and the bot, processes them using a cryptographic hashing algorithm (SHA-256), and generates a unique 256-bit key. This key can then be used in encryption processes, such as AES (Advanced Encryption Standard), to secure files.
              async function generateKeyFromMoves(userMoves, botMoves) {
                const combinedMoves = userMoves.concat(botMoves).join("");
                const msgUint8 = new TextEncoder().encode(combinedMoves);
                const hashBuffer = await crypto.subtle.digest("SHA-256", msgUint8);
                return hashBuffer.slice(0, 32); // AES key requires 256 bits
              }
            

    1. Input Data and Combine It:

    const combinedMoves = userMoves.concat(botMoves).join("");
    These moves are stored as arrays of strings.

    2. Encoding to Binary Format:

    const msgUint8 = new TextEncoder().encode(combinedMoves);

    3. Hashing the Data:

    const hashBuffer = await crypto.subtle.digest("SHA-256", msgUint8);

    4. Extracting the Key:

    return hashBuffer.slice(0, 32); // AES key requires 256 bits

    3. File Encryption: The file is encrypted using the generated key.

    This code demonstrates a JavaScript function, encryptFile, that encrypts a file uploaded by the user using the AES-GCM algorithm.
              async function encryptFile() {
                            
                  const fileInput = document.getElementById("fileInput").files[0];
                  // Generate encryption key
                  const keyBuffer = await generateKeyFromMoves(userMoves, botMoves);
                  const key = await crypto.subtle.importKey("raw", keyBuffer, "AES-GCM", false, ["encrypt"]);
                  const iv = crypto.getRandomValues(new Uint8Array(12)); // IV for AES-GCM
                  const fileData = await fileInput.arrayBuffer();
                  const encryptedData = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, fileData);
                  const combined = new Uint8Array(iv.length + encryptedData.byteLength);
                  combined.set(iv);
                  combined.set(new Uint8Array(encryptedData), iv.length);
                          
                  downloadFile(combined, "castlefile_" + fileInput.name + ".enc.txt");
              }
            

    1. File Selection

    const fileInput = document.getElementById("fileInput").files[0];

    2. Generate Encryption Key:

    const keyBuffer = await generateKeyFromMoves(userMoves, botMoves);
    const key = await crypto.subtle.importKey("raw", keyBuffer, "AES-GCM", false, ["encrypt"]);

    3. Generate IV (Initialization Vector):

    const iv = crypto.getRandomValues(new Uint8Array(12));

    4. Read and Encrypt the File:

    const fileData = await fileInput.arrayBuffer();
    const encryptedData = await crypto.subtle.encrypt({ name: "AES-GCM", iv }, key, fileData);

    5. Combine IV and Encrypted Data:

    const combined = new Uint8Array(iv.length + encryptedData.byteLength);
    combined.set(iv);
    combined.set(new Uint8Array(encryptedData), iv.length);
    

    6. Download the Encrypted File:

    downloadFile(combined, "castlefile_" + fileInput.name + ".enc.txt");

    4. File Decryption: The encrypted file is decrypted using the regenerated key.

    This JavaScript function, decryptFile, is designed to decrypt a file encrypted using the AES-GCM algorithm. It relies on the user-provided and bot-generated chess moves to reconstruct the encryption key, ensuring the correct moves are essential for successful decryption.
              async function decryptFile() {
                  const fileInput = document.getElementById("fileInput").files[0];
                  const keyBuffer = await generateKeyFromMoves(userMoves, botMoves);
                  const key = await crypto.subtle.importKey("raw", keyBuffer, "AES-GCM", false, ["decrypt"]);
                  const fileData = await fileInput.arrayBuffer();
                  const iv = fileData.slice(0, 12); // First 12 bytes are the IV
                  const encryptedData = fileData.slice(12);
        
                  try {
                    const decryptedData = await crypto.subtle.decrypt({ name: "AES-GCM", iv: new Uint8Array(iv) }, key, encryptedData);
                    downloadFile(decryptedData, fileInput.name.replace(".enc.txt", ""));
                    
                  } catch (error) {
                    console.log(error);
                  }
              }
            

    1. Retrieve the File to Decrypt:

    const fileInput = document.getElementById("fileInput").files[0];

    2. Generate the Decryption Key:

    const keyBuffer = await generateKeyFromMoves(userMoves, botMoves);
    const key = await crypto.subtle.importKey("raw", keyBuffer, "AES-GCM", false, ["decrypt"]);

    3. Read and Separate the File Data:

    const fileData = await fileInput.arrayBuffer();
    const iv = fileData.slice(0, 12); // First 12 bytes are the IV
    const encryptedData = fileData.slice(12);

    4. Decrypt the File:

    const decryptedData = await crypto.subtle.decrypt({ name: "AES-GCM", iv: new Uint8Array(iv) }, key, encryptedData);

    5. Download the Decrypted File:

    downloadFile(decryptedData, fileInput.name.replace(".enc.txt", ""));

    6. Handle Errors:

    
    catch (error) {
      console.log(error);
    }

    5. Download: The Encrypted or Decrypted file is Downloaded.

    This JavaScript function, downloadFile, handles the task of downloading a file from the browser. It takes two parameters: the data to be downloaded and the filename to save it as.
              function downloadFile(data, filename) {
                try {
                    const blob = new Blob([data], { type: "application/octet-stream" });
                    const url = URL.createObjectURL(blob);
            
                    // Trigger download
                    const a = document.createElement("a");
                    a.href = url;
                    a.download = filename;
                    document.body.appendChild(a);
                    a.click();
            
                    // Clean up
                    document.body.removeChild(a);
                    URL.revokeObjectURL(url); // Revoke the Blob URL after use
                    
                } catch (error) {
                    console.error("Download error:", error);
                }
              }
            

    1. Create a Blob:

    const blob = new Blob([data], { type: "application/octet-stream" });

    2. Generate a Blob URL and Create a Hidden <'a'> Element:

    const url = URL.createObjectURL(blob);

    3. Assign Blob URL and Filename:

    a.href = url;
    a.download = filename;

    4. Trigger the Download:

    document.body.appendChild(a);
    a.click();

    5. Clean Up Resources:

    document.body.removeChild(a);
    URL.revokeObjectURL(url);

    6. Handle Errors:

    
    catch (error) {
      console.log(error);
    }

    Credits


    Chess.js

    The functioning of Chess pieces on Chessboard is done with the help of Chess.js library

    Chessboard.js

    The design of Chess pieces and Chessboard is done with the help of Chessboard.js library

    Chess and Chessboard

    The blend of chess.js functioning and chessboard.js design of Chess and Chessboard is adapted from zeyu2001

    Chess Piece Square Table

    Chess Piece Square Tables, is adapted from Sunfish.py