Example #1
0
        public static void DecryptFile(string sInputFilename, string sOutputFilename, UserCryptor userCryptor)
        {
            // Must be 64 bits, 8 bytes.
            // Distribute this key to the user who will decrypt this file.
            string sSecretKey;

            // Get the key for the file to encrypt.
            sSecretKey = userCryptor.DecryptKey(ResolveKeyFileNameForDecode(sInputFilename, userCryptor.UserId));

            // For additional security pin the key.
            GCHandle gch = GCHandle.Alloc(sSecretKey, GCHandleType.Pinned);

            // Decrypt the file.
            Decrypt(sInputFilename, sOutputFilename, sSecretKey);

            // Remove the key from memory.
            ZeroMemory(gch.AddrOfPinnedObject(), sSecretKey.Length * 2);
            gch.Free();
        }
Example #2
0
        public static string PrepareKeyForSharing(string sInputFilename, UserCryptor decryptor, UserCryptor encryptor)
        {
            // Must be 64 bits, 8 bytes.
            // Distribute this key to the user who will decrypt this file.
            string sSecretKey;

            // Get the key for the file to encrypt.
            sSecretKey = decryptor.DecryptKey(ResolveKeyFileNameForDecode(sInputFilename, decryptor.UserId));

            // For additional security pin the key.
            GCHandle gch = GCHandle.Alloc(sSecretKey, GCHandleType.Pinned);

            string keyFilename = ResolveKeyFileNameForDecode(sInputFilename, encryptor.UserId);

            encryptor.EncryptKey(sSecretKey, keyFilename);

            // Remove the key from memory.
            ZeroMemory(gch.AddrOfPinnedObject(), sSecretKey.Length * 2);
            gch.Free();

            return(keyFilename);
        }