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 ...
随机推荐
- Python学习--内置函数isinstance()
内置函数isinstance() isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type(). isinstance() 与 type() 区别: type() 不会认为子类 ...
- Springboot笔记(二)整合
1.整合Freemarker 一种模板引擎,前端渲染模板的,类似于EL,jsp,不过比前两个好用 导入很简单 pom.xml <dependency> <groupId>o ...
- (三)(2)wait/notify实现生产者-消费者模型,join方法
生产者,消费者模型 举个例子来说明,厨师,服务员,厨师做菜,服务员上菜,如果厨师没有做好菜,那么服务员就无法上菜,厨师做好了菜,然后通知服务员消费(上菜).在这个过程之中,厨师扮演的就是生产者,服务员 ...
- 必知必会之Lambda表达式
Java是一门强大的面向对象的语言,除了8种基本的数据类型,其他一切皆为对象.因此,在Java中定义函数或方法都离不开对象,也就意味着很难直接将方法或函数像参数一样传递,而Java8中的Lambda表 ...
- [Effective Java 读书笔记] 第二章 创建和销毁对象 第五条
第五条 避免创建不必要的对象 书中一开始举例: String s = new String("stringette"); // don't do this //应该使用下面,只会创 ...
- php 页面分页样式 示例
<?php class SubPages { private $each_disNums; //每页显示的条目数 private $nums; //总条目数 private $current_p ...
- SELinux 和 iptables 开启关闭
SELinux 是 2.6 版本的 Linux 内核中提供的强制访问控制(MAC)系统.对于目前可用的 Linux安全模块来说,SELinux 是功能最全面,而且测试最充分的,它是在 20 年的 MA ...
- 在Windows系统中安装Redis和php_redis扩展
安装Redis (1)下载redis压缩包,git下载地址https://github.com/MSOpenTech/redis/releases 解压文件夹,在文件夹中运行cmd命令: 输入: ...
- 07_TypeScript命名空间
命名空间:内部模块,主要用于组织代码,避免命名冲突. 关键字:namespace //俩个类命名冲突 class Dog{ name: string; constructor(name: string ...
- 14.git的安装使用
目录 一.版本控制器 二.git 简介 git与svn比较 git的工作流程 版本库间的通信 git分支管理 三.git使用 流程(核心总结) 安装 基础命令 将已有的文件夹 - 初始化为git仓库 ...