Ejemplo n.º 1
0
        public static void EncryptFile(string sInputFilename, 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 = GenerateKey();

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

            userCryptor.EncryptKey(sSecretKey, ResolveKeyFileNameForEncode(sInputFilename, userCryptor.UserId));

            // Encrypt the file.
            Encrypt(sInputFilename, sInputFilename + DRIVE_CRYPT_EXTENSTION, sSecretKey);

            // Remove the key from memory.
            ZeroMemory(gch.AddrOfPinnedObject(), sSecretKey.Length * 2);
            gch.Free();
        }
Ejemplo n.º 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);
        }