using System;
using System.Text;
using System.IO;
using System.Security.Cryptography; static void Main(string[] args)
{
CompareFileGetBytes("lyf.txt");
Console.ReadLine();
} static void CompareFileGetBytes(string fileFullName)
{
byte[] fileReadAllBytes = File.ReadAllBytes(fileFullName);
string fileReadAllBytesMd5 = GetBytesMd5(fileReadAllBytes); string utf8Md5 = string.Empty;
using (StreamReader reader = new StreamReader(fileFullName))
{
string textResult = reader.ReadToEnd();
byte[] utf8Bytes = Encoding.UTF8.GetBytes(textResult);
utf8Md5 = GetBytesMd5(utf8Bytes);
} string utf32Md5 = string.Empty;
using (StreamReader utf32Reader = new StreamReader(fileFullName))
{
string textResult = utf32Reader.ReadToEnd();
byte[] utf32Bytes = Encoding.UTF32.GetBytes(textResult);
utf32Md5 = GetBytesMd5(utf32Bytes);
} Console.WriteLine($"fileReadAllBytesMd5:{fileReadAllBytesMd5},utf8Md5:{utf8Md5}"); if (string.Equals(fileReadAllBytesMd5, utf8Md5))
{
Console.WriteLine($"{nameof(fileReadAllBytesMd5)} is equal with {nameof(utf8Md5)}!");
}
else
{
Console.WriteLine($"{nameof(fileReadAllBytesMd5)} is not equal with {nameof(utf8Md5)}!");
} Console.WriteLine($"utf8Md5:{utf8Md5},utf32Md5:{utf32Md5}");
if (string.Equals(utf8Md5, utf32Md5))
{
Console.WriteLine($"{nameof(utf8Md5)} is equals with {nameof(utf32Md5)}");
}
else
{
Console.WriteLine($"{nameof(utf8Md5)} is not equals with {nameof(utf32Md5)}");
}
} static string GetBytesMd5(byte[] bytesData)
{
StringBuilder md5Builder = new StringBuilder();
using(MD5CryptoServiceProvider md5=new MD5CryptoServiceProvider())
{
byte[] md5Bytes = md5.ComputeHash(bytesData);
for(int i=;i<md5Bytes.Length;i++)
{
md5Builder.Append(md5Bytes[i].ToString("x2"));
}
}
return md5Builder.ToString();
}

I had validated that different encoding mode can generate different result,they are not identical.

Besides,the File.ReadAllBytes may based on UTF8 because they render the identical result!

C# compare different Encoding pattern between UTF8 and UTF32 based on Md5的更多相关文章

  1. Unicode Character Set and UTF-8, UTF-16, UTF-32 Encoding

    在计算机内存中,统一使用unicode编码,当需要保存到硬盘或者需要传输的时候,就转换为utf-8编码. 用记事本编辑的时候,从文件读取的utf-8字符被转换为unicode字符到内存里,编码完成保存 ...

  2. 细说:Unicode, UTF-8, UTF-16, UTF-32, UCS-2, UCS-4

    1. Unicode与ISO 10646 全世界很多个国家都在为自己的文字编码,并且互不想通,不同的语言字符编码值相同却代表不同的符号(例如:韩文编码EUC-KR中“한국어”的编码值正好是汉字编码GB ...

  3. UTF-8, UTF-16, UTF-32 & BOM

    FAQ - UTF-8, UTF-16, UTF-32 & BOM http://www.unicode.org/faq/utf_bom.html General questions, rel ...

  4. UTF-8/UTF-16/UTF-32

    UTF-8/UTF-16/UTF-32 一.UTF-8/UTF-16/UTF-32三者的区别 二.BOM的检测与删除 1.用VIM去除<feff>,即 U+FEFF.注意:这是一个字符,而 ...

  5. Unicode 与 utf8 utf16 utf32的关系

    Unicode是计算机领域的一项行业标准,它对世界上绝大部分的文字的进行整理和统一编码,Unicode的编码空间可以划分为17个平面(plane),每个平面包含2的16次方(65536)个码位.17个 ...

  6. 关于编码:Unicode/UTF-8/UTF-16/UTF-32

    关于编码,绕不开下面这些概念 ①Unicode/UTF-8/UTF-16/UTF-32 ②大小端字节序(big-endian/little-endian) ③BOM(Byte Order Mark) ...

  7. Unicode与UTF-8/UTF-16/UTF-32的区别

    Unicode的最初目标,是用1个16位的编码来为超过65000字符提供映射.但这还不够,它不能覆盖全部历史上的文字,也不能解决传输的问题 (implantation head-ache's),尤其在 ...

  8. UTF8,UTF16,UTF32,UTF16-LE,UTF16-BE,GBK 之间的转换

    Unicode是Unicode.org制定的编码标准,目前得到了绝大部分操作系统和编程语言的支持.Unicode.org官方对Unicode的定义是:Unicode provides a unique ...

  9. Unicode 与 Unicode Transformation Format(UTF,UTF-8 / UTF-16 / UTF-32)

    ASCII(American Standard Code for Information Interchange):早期它使用7 bits来表示一个字符,总共表示27 = 128个字符:后来扩展到8 ...

随机推荐

  1. HDU_2167_状态压缩dp

    http://acm.hdu.edu.cn/showproblem.php?pid=2167 第一道状态压缩dp,其实就是爆搜,只不过把排除了大量不可能的情况,先用sta保存每行可能的情况,sum[i ...

  2. ARTS Week 12

    Jan 13, 2020 ~ Jan 19, 2020 Algorithm Problem 112. Path Sum (路径总和) 题目链接 题目描述:给定一棵二叉树和一个值 sum ,检查二叉树是 ...

  3. 批处理(BAT) Ping监控, 结果记录入日志文件

    ::执行效果 @echo off ::等待用户输入需要监控IP set /p ip=Input the IP required to monitor: echo executing...... :st ...

  4. angularJS 传参的四种方法 【修改】

    1. 基于ui-router的页面跳转传参(1) 在AngularJS的app.js中用ui-router定义路由,比如现在有两个页面,一个页面(producers.html)放置了多个produce ...

  5. 深入理解ASP.NET Core依赖注入

    概述        ASP.NET Core可以说是处处皆注入,本文从基础角度理解一下原生DI容器,及介绍下怎么使用并且如何替换官方提供的默认依赖注入容器. 什么是依赖注入        百度百科中对 ...

  6. Unity酱~ 卡通渲染技术分析(二)

    前面的话 上一篇Unity酱~ 卡通渲染技术分析(一) 写了CharaMain.cginc,服装的渲染是怎么实现的.这篇来分析一下头发跟皮肤的实现 头发 本来以为unitychan的头发会有各向异性的 ...

  7. 数据算法 --hadoop/spark数据处理技巧 --(17.小文件问题 18.MapReuce的大容量缓存)

    十七.小文件问题 十八.MR的大容量缓存 在MR中使用和读取大容量缓存,(也就是说,可能包括数十亿键值对,而无法放在一个商用服务器的内存中).本次提出的算法通用,可以在任何MR范式中使用.(eg:MR ...

  8. 一起了解 .Net Foundation 项目 No.5

    .Net 基金会中包含有很多优秀的项目,今天就和笔者一起了解一下其中的一些优秀作品吧. 中文介绍 中文介绍内容翻译自英文介绍,主要采用意译.如与原文存在出入,请以原文为准. Couchbase Lit ...

  9. vue垂死挣扎系列(一)——vue-cli快速搭建

    项目安装(windows10安装环境+vue-cli 2.x) 安装node 在官网上下载稳定版本的node node.js官网 一路傻瓜安装 测试是否安装成功 cmd中node --version ...

  10. js—求数组中的最大最小值

    参考链接:https://www.w3cplus.com/javascript/calculate-the-max-min-value-from-an-array.html Math.min.appl ...