Ejemplo n.º 1
0
        /// <summary>
        ///     整体加密文件
        /// </summary>
        /// <param name="sourceFile">待加密的文件名</param>
        /// <param name="targetFile">保存加密文件名</param>
        /// <param name="key">密钥字符串,长度为8或者24</param>
        public static void EncryptFile(string sourceFile, string targetFile, string key)
        {
            sourceFile.CheckFileExists(nameof(sourceFile));
            targetFile.CheckNotNullOrEmpty(nameof(targetFile));
            key.CheckNotNullOrEmpty(nameof(key));

            var keyBytes = Encoding.UTF8.GetBytes(key);
            var des      = new DesHelper(keyBytes);

            des.EncryptFile(sourceFile, targetFile);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     分段加密文件
        /// </summary>
        /// <param name="sourceFile">待加密的文件名</param>
        /// <param name="targetFile">保存加密文件名</param>
        /// <param name="sectionLength">分段大小(字节)</param>
        /// <param name="key">密钥字符串,长度为8或者24</param>
        public static void EncryptFile(string sourceFile, string targetFile, int sectionLength, string key)
        {
            sourceFile.CheckFileExists(nameof(sourceFile));
            targetFile.CheckNotNullOrEmpty(nameof(targetFile));
            key.CheckNotNullOrEmpty(nameof(key));
            sectionLength.CheckGreaterThan(nameof(sectionLength), 0);

            var keyBytes = Encoding.UTF8.GetBytes(key);
            var des      = new DesHelper(keyBytes);

            des.EncryptFile(sourceFile, targetFile, sectionLength);
        }