Exemplo n.º 1
0
        public static void openSharedFile(string filePath)
        {
            BinaryFormatter formatter         = new BinaryFormatter();
            FileStream      streamOfLocalFile = new FileStream(filePath, FileMode.Open, FileAccess.Read);

            EncryptedFile file       = (EncryptedFile)formatter.Deserialize(streamOfLocalFile);
            string        senderName = Encoding.UTF8.GetString(file.getSender());

            streamOfLocalFile.Close();

            var userCertTuple = LogIn.getUserCertificateTuples();
            X509Certificate2 senderCertificate = null;

            foreach (var x in userCertTuple)
            {
                if (x.Item1 == senderName)
                {
                    senderCertificate = LogIn.getUsersCertificateByName(senderName);
                    break;
                }
            }
            if (senderCertificate == null)
            {
                throw new CryptographicException("Sender's certificate not found");
            }
            byte[] decryptedFileContent = Decrypt.decryptSharedFile(file, senderCertificate);

            string newTempFileName = System.IO.Path.GetTempFileName() + Guid.NewGuid().ToString() + Path.GetExtension(filePath);

            File.WriteAllBytes(newTempFileName, decryptedFileContent);

            Process fileopener = new Process();

            fileopener.StartInfo.FileName  = "explorer";
            fileopener.StartInfo.Arguments = "\"" + newTempFileName + "\"";
            fileopener.Start();
        }