コード例 #1
0
 //Added size return, since symbolic links return 0, we use this function also to return the size of the file.
 private long CanAccessFile(string fileName)
 {
     try
     {
         using (FileStream fs = File.Open(fileName, FileMode.Open, FileAccess.Read, FileShare.None))
         {
             long size = fs.Seek(0, SeekOrigin.End);
             fs.Close();
             return(size);
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.Message);
         return(0);
     }
 }
コード例 #2
0
            /// <summary>
            /// Transforms a file into its cryptographically strong equivalent using AES256 in CBC mode.
            /// </summary>
            /// <param name="originalFile">The path to the file to be cryptographically transformed.</param>
            /// <param name="encryptedFile">The path where the new file will be created.</param>
            /// <param name="password">The key to be used during the cryptographic transformation.</param>
            /// <returns>A flag determining whether or not the operation was successful.</returns>
            public static bool EncryptFile(string originalFile, string encryptedFile, byte[] password)
            {
                try
                {
                    string originalFilename  = originalFile;
                    string encryptedFilename = encryptedFile;

                    using (var originalStream = LongFile.Open(originalFile, FileMode.Open))
                        using (var encryptedStream = LongFile.Create(encryptedFile, 8192))
                            using (var encTransform = new EtM_EncryptTransform(key: password))
                                using (var crypoStream = new CryptoStream(encryptedStream, encTransform, CryptoStreamMode.Write))
                                {
                                    originalStream.CopyTo(crypoStream);
                                }
                    return(true);
                }
                catch { return(false); }
            }
コード例 #3
0
            /// <summary>
            /// Asynchronously transforms a file into its cryptographically strong equivalent using AES256 in CBC mode.
            /// </summary>
            /// <param name="originalFile">The path to the file to be cryptographically transformed.</param>
            /// <param name="encryptedFile">The path where the new file will be created.</param>
            /// <param name="password">The key to be used during the cryptographic transformation.</param>
            /// <returns>A flag determining whether or not the operation was successful.</returns>
            public static async Task <bool> EncryptFileAsync(string originalFile, string encryptedFile, string password)
            {
                try
                {
                    string originalFilename  = originalFile;
                    string encryptedFilename = encryptedFile;

                    using (var originalStream = LongFile.Open(originalFile, FileMode.Open))
                        using (var encryptedStream = LongFile.Create(encryptedFile, 8192))
                            using (var encTransform = new EtM_EncryptTransform(key: password.ToBytes()))
                                using (var crypoStream = new CryptoStream(encryptedStream, encTransform, CryptoStreamMode.Write))
                                {
                                    await originalStream.CopyToAsync(crypoStream);

                                    return(true);
                                }
                }
                catch { return(false); }
            }
コード例 #4
0
ファイル: FileTests.cs プロジェクト: tmct/LongPath
        public void TestOpenWithAccess()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append(Path.GetRandomFileName()).ToString();

            try
            {
                using (var s = File.Create(tempLongPathFilename))
                {
                    s.WriteByte(42);
                }
                using (File.Open(tempLongPathFilename, FileMode.Open, FileAccess.Read))
                {
                }
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
コード例 #5
0
ファイル: FileTests.cs プロジェクト: tmct/LongPath
        public void TestOpenExisting()
        {
            var tempLongPathFilename = new StringBuilder(longPathDirectory).Append(@"\").Append("filename.ext").ToString();

            try
            {
                using (var s = File.Create(tempLongPathFilename))
                {
                    s.WriteByte(42);
                }
                using (var stream = File.Open(tempLongPathFilename, FileMode.Open))
                {
                    Assert.IsNotNull(stream);
                }
            }
            finally
            {
                File.Delete(tempLongPathFilename);
            }
        }
コード例 #6
0
            /// <summary>
            /// Asynchronously transforms a cryptographic file into its original form using AES256 in CBC mode.
            /// </summary>
            /// <param name="originalFile">The path to the file to be transformed into its decrypted form.</param>
            /// <param name="decryptedFile">The location the decrypted file will be written to.</param>
            /// <param name="password">The key to use during the cryptographic transformation.</param>
            /// <returns>A flag determining whether or not the operation was successful or not.</returns>
            public static async Task <bool> DecryptFileAsync(string originalFile, string decryptedFile, byte[] password)
            {
                try
                {
                    string originalFilename  = originalFile;
                    string decryptedFilename = decryptedFile;

                    using (var encryptedStream = LongFile.Open(originalFilename, FileMode.Open))
                        using (var decryptedStream = LongFile.Create(decryptedFilename, 8192))
                            using (var decTransform = new EtM_DecryptTransform(key: password))
                            {
                                using (var cryptoStream = new CryptoStream(encryptedStream, decTransform, CryptoStreamMode.Read))
                                    await cryptoStream.CopyToAsync(decryptedStream);

                                if (!decTransform.IsComplete)
                                {
                                    throw new Exception("Not all blocks have been decrypted.");
                                }
                            }
                    return(true);
                }
                catch { return(false); }
            }
コード例 #7
0
ファイル: zFile.cs プロジェクト: 24/source_04
 public static FileStream Open(string path, FileMode mode, FileAccess access, FileShare share, int bufferSize)
 {
     return(File.Open(path, mode, access, share, bufferSize));
 }
コード例 #8
0
ファイル: zFile.cs プロジェクト: 24/source_04
 public static FileStream Open(string path, FileMode mode, FileAccess access)
 {
     return(File.Open(path, mode, access));
 }
コード例 #9
0
ファイル: zFile.cs プロジェクト: 24/source_04
 public static FileStream Open(string path, FileMode mode)
 {
     return(File.Open(path, mode));
 }
コード例 #10
0
 public PsStream(string filenamePath)
 {
     this.fileStream = File.Open(filenamePath, FileMode.Open, FileAccess.Read, FileShare.Read);
     this._length    = new FileInfo(filenamePath).Length;
 }