Basic self_encryptor example DIY instructions

thanks to @dallyshalla I just got motivated to play with the ‘basic_encryptor’ example myself: I encrypted a 176MB music file, got back 168 encrypted chunks and a 49KB datamap. After that I decrypted the datamap and got a restored copy of my music file. I am listening to it right now. To play around with it yourself:

  1. install rust Nightly (the compiler) Install Rust - Rust Programming Language or on mac/linux
    curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --channel=nightly

  2. install gcc (linux sudo apt-get install gcc / windows one example)

  3. clone self_encryption (install git if you don’t have it sudo apt-get install git on linux)
    git clone http://github.com/maidsafe/self_encryption.git

  4. go into the folder:
    cd self_encryption

  5. encrypt a file with the example basic_encryptor by
    cargo run --example basic_encryptor -- -e <full_path_to_my_file>

You now have the executable in ../self_encryption/target/debug/examples/. Your data_map and folder with the encrypted chunks is written where you ran the example from.

  1. to decrypt your file, run
    cargo run --example basic_encryptor -- -d <full_path_to>/data_map <full_destination_path_including_filename>

That will restore your file :smile: . Bear in mind that this example has not been optimized for multithreading, so it runs slower then it will after optimization.

17 Likes

Please let me know if it contains errors; this should work on all supported platforms, but I have not tested these instructions on all platforms.

I’m using fedora 21 as my distro. So what adaptations would I need to make to these instructions for that? Obviously I’d be using yum instead of apt-get but what else?

Also can you encrypt a whole folder full of data or just individual files? And this has me real excited because even the self encryption alone is awesome. We haven’t had a decent cross platform encryption protocol since Trucrypt was made obsolete and went out of business.

3 Likes

Any idea?

infinity@infinity-All-Series ~/self_encryption $ cargo run --example basic_encryptor – -e file:///home/infinity/Downloads/translation.pdf
Updating registry https://github.com/rust-lang/crates.io-index
Compiling libc v0.1.6
Compiling regex v0.1.30
Compiling byteorder v0.3.9
Compiling gcc v0.3.5
Compiling rustc-serialize v0.3.14
Compiling strsim v0.3.0
Compiling rand v0.3.8
Compiling time v0.1.25
error: linking with cc failed: exit code: 1
note: “cc” “-Wl,–as-needed” “-m64” “-L” “/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib” “-o” “/home/infinity/self_encryption/target/debug/build/time-e758cbe877e9589d/build_script_build” “/home/infinity/self_encryption/target/debug/build/time-e758cbe877e9589d/build_script_build.o” “-Wl,–whole-archive” “-lmorestack” “-Wl,–no-whole-archive” “-Wl,–gc-sections” “-pie” “-nodefaultlibs” “/home/infinity/self_encryption/target/debug/deps/libgcc-982b24959a427c6e.rlib” “-L” “/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib” “-lstd-4e7c5e5c” “-L” “/home/infinity/self_encryption/target/debug/deps” “-L” “/home/infinity/self_encryption/target/debug/deps” “-L” “/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib” “-L” “/home/infinity/self_encryption/.rust/lib/x86_64-unknown-linux-gnu” “-L” “/home/infinity/self_encryption/lib/x86_64-unknown-linux-gnu” “-Wl,–whole-archive” “-Wl,-Bstatic” “-Wl,–no-whole-archive” “-Wl,-Bdynamic” “-ldl” “-lpthread” “-lrt” “-lgcc_s” “-lpthread” “-lc” “-lm” “-lcompiler-rt”
note: /usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lrt
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lc
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

error: aborting due to previous error
Compiling rust-crypto v0.2.31
error: linking with cc failed: exit code: 1
note: “cc” “-Wl,–as-needed” “-m64” “-L” “/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib” “-o” “/home/infinity/self_encryption/target/debug/build/rust-crypto-67f1ad94f3ffe5f4/build_script_build” “/home/infinity/self_encryption/target/debug/build/rust-crypto-67f1ad94f3ffe5f4/build_script_build.o” “-Wl,–whole-archive” “-lmorestack” “-Wl,–no-whole-archive” “-Wl,–gc-sections” “-pie” “-nodefaultlibs” “/home/infinity/self_encryption/target/debug/deps/libgcc-982b24959a427c6e.rlib” “-L” “/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib” “-lstd-4e7c5e5c” “-L” “/home/infinity/self_encryption/target/debug/deps” “-L” “/home/infinity/self_encryption/target/debug/deps” “-L” “/usr/local/lib/rustlib/x86_64-unknown-linux-gnu/lib” “-L” “/home/infinity/self_encryption/.rust/lib/x86_64-unknown-linux-gnu” “-L” “/home/infinity/self_encryption/lib/x86_64-unknown-linux-gnu” “-Wl,–whole-archive” “-Wl,-Bstatic” “-Wl,–no-whole-archive” “-Wl,-Bdynamic” “-ldl” “-lpthread” “-lrt” “-lgcc_s” “-lpthread” “-lc” “-lm” “-lcompiler-rt”
note: /usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
/usr/bin/ld: cannot find -ldl
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lrt
/usr/bin/ld: cannot find -lpthread
/usr/bin/ld: cannot find -lc
/usr/bin/ld: cannot find -lm
/usr/bin/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status

error: aborting due to previous error
Compiling tempdir v0.3.4
Build failed, waiting for other jobs to finish…
Could not compile time.

To learn more, run the command again with --verbose.
infinity@infinity-All-Series ~/self_encryption $

1 Like

We currently don’t actively support Fedora as we want to move forward as fast as possible. But if you try and report back, we’ll be happy to help along. I think others have also already tried rust on Fedora. The commands should largely be identical (excepting yum for example).

1 Like

if you had rust installed some time ago, first call of action should be to update the nightly again to a more recent version; but equally you might want to run cargo update to update all the dependencies to their latest versions.

please also share rustc --version

If you just now installed rustc, tell me what system you are running

1 Like

I just followed your instructions today, nothing rust related, clean ubuntu 14.04 machine

rustc 1.1.0-nightly (c4b23aec4 2015-04-29) (built 2015-04-29)

parallels@ubuntu:~/self_encryption$ cargo run --example basic_encryptor – -e home/parallels/Desktop/Solution_Guide.pdf
Updating registry https://github.com/rust-lang/crates.io-index
Downloading rand v0.3.8
Downloading regex v0.1.30
Downloading time v0.1.25
Downloading rustc-serialize v0.3.14
Downloading byteorder v0.3.9
Downloading tempdir v0.3.4
Downloading libc v0.1.6
Downloading gcc v0.3.5
Downloading rust-crypto v0.2.31
Downloading strsim v0.3.0
Downloading docopt v0.6.64
Downloading cbor v0.3.6
Compiling strsim v0.3.0
Compiling byteorder v0.3.9
Compiling libc v0.1.6
Compiling gcc v0.3.5
Compiling regex v0.1.30
Compiling rustc-serialize v0.3.14
Compiling rand v0.3.8
Compiling rust-crypto v0.2.31
Compiling time v0.1.25
Compiling tempdir v0.3.4
Compiling docopt v0.6.64
Compiling cbor v0.3.6
Compiling self_encryption v0.1.1 (file:///home/parallels/self_encryption)
Running target/debug/examples/basic_encryptor -e home/parallels/Desktop/Solution_Guide.pdf
thread ‘’ panicked at ‘couldn’t open home/parallels/Desktop/Solution_Guide.pdf’, examples/basic_encryptor.rs:130
An unknown error occurred

To learn more, run the command again with --verbose.

1 Like

missing / at start of your path :wink:

2 Likes

you will need gcc installed for this to work (for the linker at least)

3 Likes

just make sure you have basic gcc and git installed etc. and then type curl -s https://static.rust-lang.org/rustup.sh | sudo sh -s -- --channel=nightly to install rust and you should be good to go.

2 Likes

sorry folks, I missed out mentioning gcc. My bad

1 Like

One Windows 7 64, I am getting the following error when I attempt to follow the instructions above. It appears to be unhappy with the time library. Any ideas?

Edit: My Rust version is cargo 0.2.0-nightly (dac600c 2015-04-22) (built 2015-04-27)

===========================
$ cargo run --example basic_encryptor – -e c:\cube-pin-backing.png
Compiling rustc-serialize v0.3.14
Compiling byteorder v0.3.9
Compiling strsim v0.3.0
Compiling regex v0.1.30
Compiling gcc v0.3.5
Compiling rand v0.3.8
Compiling rust-crypto v0.2.31
Compiling time v0.1.25
Compiling tempdir v0.3.4
Build failed, waiting for other jobs to finish…
failed to run custom build command for time v0.1.25
Process didn’t exit successfully: C:\Dropbox\maidsafe\self_encryption\target\de bug\build\time-e758cbe877e9589d\build-script-build (exit code: 101)
— stdout
TARGET = Some(“x86_64-pc-windows-gnu”)
CARGO_MANIFEST_DIR = Some(“c:/Users/tcarlson\.cargo\registry\src\github.com-
1ecc6299db9ec823\time-0.1.25”)
OUT_DIR = Some(“C:\Dropbox\maidsafe\self_encryption\target\debug\build\ti
me-e758cbe877e9589d\out”)
TARGET = Some(“x86_64-pc-windows-gnu”)
OPT_LEVEL = Some(“0”)
PROFILE = Some(“debug”)
debug 0
TARGET = Some(“x86_64-pc-windows-gnu”)
HOST = Some(“x86_64-pc-windows-gnu”)
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
TARGET = Some(“x86_64-pc-windows-gnu”)
HOST = Some(“x86_64-pc-windows-gnu”)
CFLAGS_x86_64-pc-windows-gnu = None
CFLAGS_x86_64_pc_windows_gnu = None
HOST_CFLAGS = None
CFLAGS = None
TARGET = Some(“x86_64-pc-windows-gnu”)
HOST = Some(“x86_64-pc-windows-gnu”)
CC_x86_64-pc-windows-gnu = None
CC_x86_64_pc_windows_gnu = None
HOST_CC = None
CC = None
running: “gcc” “-O0” “-c” “-ffunction-sections” “-fdata-sections” “-mwin32” “-m6
4” “-fPIC” “c:/Users/tcarlson.cargo\registry\src\github.com-1ecc6299db9ec823\ti
me-0.1.25\src/time_helpers.c” “-o” “C:\Dropbox\maidsafe\self_encryption\target\d
ebug\build\time-e758cbe877e9589d\out\src\time_helpers.o”

command did not execute successfully, got: exit code: 1

— stderr
thread ‘’ panicked at ‘explicit panic’, c:/Users/tcarlson.cargo\registry
src\github.com-1ecc6299db9ec823\gcc-0.3.5\src\lib.rs:384

===========================

You also need a gcc or equivalent. If you look in our Appveyor config you will see how we have it set automatically. You can follow the same steps manually.

Perhaps @anon86652309 or @Ross can help with explicit commands.

https://raw.githubusercontent.com/dirvine/self_encryption/master/appveyor.yml

1 Like

I have gcc. I builds a bunch of .rlib files in self_encryption/target/debug/deps. One for every “compiling” entry above. It’s just not happy when it gets to the time library.

Weird are you using the same gcc we do in appveyor, it builds and passes tests all OK.

I saw something similar before installed tdm-gcc and that sorted the GCC error

1 Like

Sorry everybody. I found my problem on StackOverflow.

I was using gcc which comes in a package called “MinGW-w64” However, when I installed it, I just clicked the defaults, and ended up with a 32 bit version of it. I reinstalled MinGW-w64, being careful to select the 64 bit version, and then changed my path to point to the new 64 bit directory. Now I’m in business!

Funny how it was happy for 9 libraries, until it got to the time library.

4 Likes

This is a really helpful post @BenMS thanks for sharing it…

If you fix up the OP you could change this to a FAQ.

2 Likes

Also @Ross we need to update instructions in the repo to help here. Perhaps the inline docs and readme ?

2 Likes

I shall update the readme :slight_smile:

2 Likes