#binary #crypt #safely #embed #file #encryption #folder

include-crypt

Safely embed files into your binary

2 releases

0.1.1 May 18, 2021
0.1.0 Feb 7, 2021

#1223 in Cryptography

Download history 648/week @ 2023-12-15 347/week @ 2023-12-22 468/week @ 2023-12-29 940/week @ 2024-01-05 694/week @ 2024-01-12 772/week @ 2024-01-19 593/week @ 2024-01-26 527/week @ 2024-02-02 635/week @ 2024-02-09 633/week @ 2024-02-16 622/week @ 2024-02-23 705/week @ 2024-03-01 611/week @ 2024-03-08 530/week @ 2024-03-15 405/week @ 2024-03-22 553/week @ 2024-03-29

2,242 downloads per month

Custom license

13KB
123 lines

Rust crates.io docs.rs

include_crypt

Safely embed files into your binary.

Example

use include_crypt::{include_crypt, EncryptedFile};

static FILE: EncryptedFile = include_crypt!("assets/file.txt");

fn main() {
    let decrypted = FILE.decrypt();
    let decrypted_str = FILE.decrypt_str();
}

You can also select an encryption algorithm and specify your custom key. In this example, the key will be randomly generated. For more information see the include-crypt/examples/ folder.

Why?

When you use include_str or include_bytes the file content will be placed in the .data section of the binary. You can then use tools like binwalk to automatically extract these files. If you included a text file, you could also use strings to find the contents.

By encrypting the file, you can essentially hide all the signatures and magic numbers that are used to identify files in the binary. Of course the bytes are still in the .data section, but now they are encrypted. If another person wanted to extract the file, they would need to manually find the code which decrypts the bytes.

Extracting the file without the tool is certainly doable for a somewhat experienced reverse engineer, but you can only do it by hand. It's essentially just security through obscurity. If you are interested, you can check out this article on how to reverse-engineer (proprietary) file formats or the Wikipedia page with a decent List of file signatures.

Features

  • compression: Compresses the file before encrypting it.
  • force-build: Always runs the proc macro. This should be used for testing, because the procedural macro doesn't detect file changes.

Dependencies

~2.5MB
~54K SLoC