C# compare different Encoding pattern between UTF8 and UTF32 based on Md5
- 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的更多相关文章
- Unicode Character Set and UTF-8, UTF-16, UTF-32 Encoding
在计算机内存中,统一使用unicode编码,当需要保存到硬盘或者需要传输的时候,就转换为utf-8编码. 用记事本编辑的时候,从文件读取的utf-8字符被转换为unicode字符到内存里,编码完成保存 ...
- 细说:Unicode, UTF-8, UTF-16, UTF-32, UCS-2, UCS-4
1. Unicode与ISO 10646 全世界很多个国家都在为自己的文字编码,并且互不想通,不同的语言字符编码值相同却代表不同的符号(例如:韩文编码EUC-KR中“한국어”的编码值正好是汉字编码GB ...
- 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 ...
- UTF-8/UTF-16/UTF-32
UTF-8/UTF-16/UTF-32 一.UTF-8/UTF-16/UTF-32三者的区别 二.BOM的检测与删除 1.用VIM去除<feff>,即 U+FEFF.注意:这是一个字符,而 ...
- Unicode 与 utf8 utf16 utf32的关系
Unicode是计算机领域的一项行业标准,它对世界上绝大部分的文字的进行整理和统一编码,Unicode的编码空间可以划分为17个平面(plane),每个平面包含2的16次方(65536)个码位.17个 ...
- 关于编码:Unicode/UTF-8/UTF-16/UTF-32
关于编码,绕不开下面这些概念 ①Unicode/UTF-8/UTF-16/UTF-32 ②大小端字节序(big-endian/little-endian) ③BOM(Byte Order Mark) ...
- Unicode与UTF-8/UTF-16/UTF-32的区别
Unicode的最初目标,是用1个16位的编码来为超过65000字符提供映射.但这还不够,它不能覆盖全部历史上的文字,也不能解决传输的问题 (implantation head-ache's),尤其在 ...
- UTF8,UTF16,UTF32,UTF16-LE,UTF16-BE,GBK 之间的转换
Unicode是Unicode.org制定的编码标准,目前得到了绝大部分操作系统和编程语言的支持.Unicode.org官方对Unicode的定义是:Unicode provides a unique ...
- Unicode 与 Unicode Transformation Format(UTF,UTF-8 / UTF-16 / UTF-32)
ASCII(American Standard Code for Information Interchange):早期它使用7 bits来表示一个字符,总共表示27 = 128个字符:后来扩展到8 ...
随机推荐
- android studio sqlite实际应用中存在的问题
原项目已上传到github long f = dbdatabase.update("user", values, "id=?", new String[]{St ...
- 51Nod 1279 扔盘子 (思维+模拟)
题意: 有口井,往里扔盘子,最多扔多少个 n<=5e5, 1s 思路: 如果比较高的地方井口比较小,那么下面的再大也没有用,只需要维护一个单调减的数组然后O(n+m)模拟即可 代码: #incl ...
- 12306 抢票系列之只要搞定RAIL_DEVICEID的来源,从此抢票不再掉线(上)
郑重声明: 本文仅供学习使用,禁止用于非法用途,否则后果自负,如有侵权,烦请告知删除,谢谢合作! 开篇明义 本文针对自主开发的抢票脚本在抢票过程中常常遇到的请求无效等问题,简单分析了 12306 网站 ...
- ajax面试要点
目录 目录 ajax是什么? 优点 缺点 ajax的工作原理 如何创建一个ajax(ajax的交互模型) ajax过程中get和post的区别 同步和异步的区别 JavaScript 的同源策略 如何 ...
- Hapi+MySql项目实战配置插件-加载文件渲染母版(三)
加载插件 一般在其它node框架下,我们安装好插件直接require('插件')就能正常使用了,但是在Hapi下我们必须要Server.register()方法,才能正常使用插件.举个例子: serv ...
- cdh集群hive升级,数据不丢失
1.下载hive-1.2.1安装包 http://archive.apache.org/dist/hive/hive-1.2.1/apache-hive-1.2.1-bin.tar.gz 2.将安装包 ...
- golang-练习ATM --面向对象实现
package utils import ( "fmt" "strings" ) type StructAtm struct { action int loop ...
- U盘模式无法引导进入pe系统
有些笔记本.一体机 特别是win8.win10系统维护时需要 通过u盘进入pe系统,就是进不去,需要到bios中更改一下设置. 1.首先我们将已经使用u启动u盘启动盘制作 ...
- NAT 地址转换
NAT功能 NAT不仅能解决了lP地址不足的问题,而且还能够有效地避免来自网络外部的攻击,隐藏并保护网络内部的计算机.1.宽带分享:这是 NAT 主机的最大功能.解决IP4地址短缺的问题 ...
- 使用A线程打印1-52,B线程打印A-Z,要求按照12A34B56C....5152Z的顺序进行交替打印
多线程同步问题,都需要用到监视器,用来监视资源是否可用.C++中使用condition_variable,Java中使用Condition来实现同步. 1. 实现思路 需要有一个全局变量控制当前该哪个 ...