예제 #1
0
        /// <summary>
        /// Shares a file with other specific user on EnigmaEfs.
        /// </summary>
        /// <param name="pathOnEfs">The name of the shared file.</param>
        /// <param name="shareUser">User you are sharing a file with.</param>
        public void Share(string pathOnEfs, UserInformation shareUser)
        {
            CertificateCheck($"You cannot share files with {shareUser.Username}.");

            var encryptedFile           = new EncryptedFile(pathOnEfs.Substring(pathOnEfs.LastIndexOf('\\') + 1).Split('.')[0]);
            var updatedEncryptedFileRaw = encryptedFile.Share(File.ReadAllBytes(pathOnEfs), currentUser.Id, shareUser.Id, currentUser.PrivateKey, shareUser.PublicKey);

            if (CanItBeStored(updatedEncryptedFileRaw.Length))
            {
                CreateFile(updatedEncryptedFileRaw, SharedDir + "\\" + encryptedFile.GetEncryptedFileFullName());

                // When first sharing a file from user folder to shared folder.
                if (pathOnEfs.Substring(0, pathOnEfs.LastIndexOf('\\')) != SharedDir)
                {
                    DeleteFile(pathOnEfs);
                }
            }
            else
            {
                throw new Exception("Insufficient storage available. File can't be updated.");
            }
        }