我正在使用iTextSharp从PDF文件中读取文本.但是,有时我无法提取文本,因为PDF文件只包含图像.我每天都下载相同的PDF文件,我想查看PDF是否已被修改.如果无法获得文本和修改日期,MD5校验和是否是判断文件是否已更改的最可靠方法?
如果是的话,一些代码样本会受到赞赏,因为我对密码学没有多少经验.
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?)表现为性能问题.
令我惊讶的是,下面的方法在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)