コード例 #1
0
        /// <summary>
        /// Encrypteds the file.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public static void EncryptedFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException();
            }
            var fileName = Path.GetFileName(filePath);

            var cryptoKey = CaesarEncryptionAlgorithm.GenerateEncryptoKey(fileName, -3);

            var outputFileName = string.Concat("E", fileName);

            EncryptFile(filePath, outputFileName, cryptoKey);
        }
コード例 #2
0
        /// <summary>
        /// Decrypteds the file.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <exception cref="FileNotFoundException">filePath
        /// or
        /// EncryptedFileNotFound</exception>
        public static void DecryptedFile(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException(nameof(filePath));
            }
            var fileName = Path.GetFileName(filePath);

            if (!fileName.StartsWith("E"))
            {
                throw new FileNotFoundException("EncryptedFileNotFound");
            }
            var originalFileName = fileName.Substring(1, fileName.Length - 1);
            var chryptoKey       = CaesarEncryptionAlgorithm.GenerateEncryptoKey(originalFileName, -3);


            var outputFileName = string.Concat("D", originalFileName);

            DecryptFile(filePath, outputFileName, chryptoKey);
        }