相关疑难解决方法(0)

计算文件的MD5校验和

我正在使用iTextSharp从PDF文件中读取文本.但是,有时我无法提取文本,因为PDF文件只包含图像.我每天都下载相同的PDF文件,我想查看PDF是否已被修改.如果无法获得文本和修改日期,MD5校验和是否是判断文件是否已更改的最可靠方法?

如果是的话,一些代码样本会受到赞赏,因为我对密码学没有多少经验.

.net c# hash md5

319
推荐指数
5
解决办法
28万
查看次数

为什么String.GetHashCode()在32位和64位版本的CLR中实现不同?

string.GetHashCode()的32位和64位版本之间的差异背后的技术原因是什么?

更重要的是,为什么64位版本在遇到NUL字符时似乎终止了它的算法?例如,在64位CLR下运行时,以下表达式都返回true.

"\0123456789".GetHashCode() == "\0987654321".GetHashCode()
"\0AAAAAAAAA".GetHashCode() == "\0BBBBBBBBB".GetHashCode()
"\0The".GetHashCode() == "\0Game".GetHashCode()
Run Code Online (Sandbox Code Playgroud)

当我们将这样的字符串用作Dictionary中的键时,这种行为(bug?)表现为性能问题.

c# clr hash

20
推荐指数
1
解决办法
2080
查看次数

string.GetHashCode()在debug vs release中返回不同的值,我该如何避免这种情况?

令我惊讶的是,下面的方法在debug和release中产生了不同的结果:

int result = "test".GetHashCode();
Run Code Online (Sandbox Code Playgroud)

有什么方法可以避免这种情况吗?

我需要一种可靠的方法来散列字符串,我需要在调试和发布模式下保持一致的值.如果可能的话,我想避免编写自己的哈希函数.

为什么会这样?

仅供参考,反射器给了我:

[ReliabilityContract(Consistency.WillNotCorruptState, Cer.MayFail), SecuritySafeCritical]
public override unsafe int GetHashCode()
{
    fixed (char* str = ((char*) this))
    {
        char* chPtr = str;
        int num = 0x15051505;
        int num2 = num;
        int* numPtr = (int*) chPtr;
        for (int i = this.Length; i > 0; i -= 4)
        {
            num = (((num << 5) + num) + (num >> 0x1b)) ^ numPtr[0];
            if (i <= 2)
            {
                break;
            }
            num2 = (((num2 << 5) + …
Run Code Online (Sandbox Code Playgroud)

c# string debugging release gethashcode

6
推荐指数
1
解决办法
2675
查看次数

标签 统计

c# ×3

hash ×2

.net ×1

clr ×1

debugging ×1

gethashcode ×1

md5 ×1

release ×1

string ×1