10

I need to load a file from an umounted TrueCrypt disk into memory. Is there any way to do this programmatically? Does TrueCrypt offer an API?

The way I believe is best for attempting this would be to mount the volume (prompting the user for a password, of course), open the file, and then unmount the volume. Is there a way to do this all automatically?

I am on Windows Vista. I have C#, Python, and Perl readily available.

brian d foy
  • 129,424
  • 31
  • 207
  • 592
MiffTheFox
  • 21,302
  • 14
  • 69
  • 94

2 Answers2

12

Can you not use the true crypt command line from say System.Diagnostics.Process?

using System;
using System.Diagnostics;

namespace Test {
    
    class TrueCrypeStart
    {
        static void Main(string[] args)
        {

            string password = getPassword(...);
            Process tc= new Process();

            tc.StartInfo.FileName   = "TrueCrypt.exe";
            tc.StartInfo.Arguments = string.Format("/v \"{0}\" /p \"{1}\" /q", ...mount info ..., password); // for quiet!

            tc.Start();
        }
    }
}
Habip Oğuz
  • 921
  • 5
  • 17
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
  • 4
    Be aware that hardcoding the password into a .NET assembly could make it easy to extract the pw by decompiling it. You should consider obfuscating your code if security is an issue. – galaktor Aug 22 '09 at 11:50
  • 3
    @galaktor - I solved that problem by omitting the /p option, allowing the user to input the password themselves directly into TrueCrypt. – MiffTheFox Nov 09 '09 at 00:16
  • But sending a password like this can be a problem because the password will be visible as pure-text: http://stackoverflow.com/questions/13279436/see-command-line-arguments-being-passed-to-a-program – Nav May 30 '13 at 09:41
  • @nav - All plain text can be a problem. This why you mitigate risk using further levels of security. For example you could avoid harcoding or use keyrings, or perhaps hardware keys. etc. etc. – Preet Sangha May 30 '13 at 09:53
  • @Preet: Thanks. In this case, would it be possible to encrypt the password (or the entire commandline string) in some way to ensure that truecrypt can be invoked from a C++ app without revealing the password? – Nav May 30 '13 at 10:22
  • @Nav - not sure - you will have to not invoke the .exe as a process, rather you'll have see if you can use the code directly. – Preet Sangha May 30 '13 at 10:26
  • @Preet. Thanks, but using the code has the restriction that I'll have to publish my code. That's what the license says, and I can't do that. – Nav May 30 '13 at 10:28
  • @Nav - then you'll have to consider an alternative such as http://stackoverflow.com/questions/4432816/truecrypt-alternative-with-api – Preet Sangha May 30 '13 at 10:29
0

TrueResize includes an open-source C# TrueCrypt library that will allow you to read the encrypted volume (without having to mount it), an additional library includes NTFS support.

Tal Aloni
  • 1,429
  • 14
  • 14