简体   繁体   English

在java中计算git packfile sha1校验和

[英]calculating a git packfile sha1 checksum in java

I am learning about the Git packfile and currently trying to reproduce (in Java) what I believe to be the SHA1 20-byte checksum for the entire packfile.我正在学习 Git 包文件,目前正在尝试(在 Java 中)重现我认为是整个包文件的 SHA1 20 字节校验和。 I take the byte array from, and including, the "PACK" 4-byte header to the end of the last packaged object's compressed data.我从“PACK”4 字节标头中获取字节数组,并将其包含到最后一个打包对象的压缩数据的末尾。 Everything I have read indicates that the next 20 bytes is the SHA1 checksum for the entire packfile.我读过的所有内容都表明接下来的 20 个字节是整个包文件的 SHA1 校验和。

The 20-byte checksum that is part of the byte array received from Git is: B910248BF9B63AC53595E3835CA57BDAF08DA830作为从 Git 收到的字节数组的一部分的 20 字节校验和是:B910248BF9B63AC53595E3835CA57BDAF08DA830

I use the following to calculate my own SHA1 checksum:我使用以下内容来计算我自己的 SHA1 校验和:
crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(testData);
byte [] result = crypt.digest();

My result ends up as: B910248BF9B63AC53595E3835CA57BDAF08DA813我的结果最终为:B910248BF9B63AC53595E3835CA57BDAF08DA813

I am baffled at how only the last byte of my result can be different from Git's (if I am using the correct part of the byte stream).我对结果的最后一个字节与 Git 的不同(如果我使用的是字节流的正确部分)感到困惑。 If the only problem was the range of data passed to digest() then the entire calculated checksum would most likely look different.如果唯一的问题是传递给digest() 的数据范围,那么整个计算的校验和很可能看起来不同。

Any ideas?有任何想法吗?

I am learning about the Git packfile and currently trying to reproduce (in Java) what I believe to be the SHA1 20-byte checksum for the entire packfile.我正在学习 Git 包文件,目前正在尝试(在 Java 中)重现我认为是整个包文件的 SHA1 20 字节校验和。 I take the byte array from, and including, the "PACK" 4-byte header to the end of the last packaged object's compressed data.我从“PACK”4 字节标头中获取字节数组,并将其包含到最后一个打包对象的压缩数据的末尾。 Everything I have read indicates that the next 20 bytes is the SHA1 checksum for the entire packfile.我读过的所有内容都表明接下来的 20 个字节是整个包文件的 SHA1 校验和。

The 20-byte checksum that is part of the byte array received from Git is: B910248BF9B63AC53595E3835CA57BDAF08DA830作为从 Git 收到的字节数组的一部分的 20 字节校验和是:B910248BF9B63AC53595E3835CA57BDAF08DA830

I use the following to calculate my own SHA1 checksum:我使用以下内容来计算我自己的 SHA1 校验和:
crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(testData);
byte [] result = crypt.digest();

My result ends up as: B910248BF9B63AC53595E3835CA57BDAF08DA813我的结果最终为:B910248BF9B63AC53595E3835CA57BDAF08DA813

I am baffled at how only the last byte of my result can be different from Git's (if I am using the correct part of the byte stream).我对结果的最后一个字节与 Git 的不同(如果我使用的是字节流的正确部分)感到困惑。 If the only problem was the range of data passed to digest() then the entire calculated checksum would most likely look different.如果唯一的问题是传递给digest() 的数据范围,那么整个计算的校验和很可能看起来不同。

Any ideas?有任何想法吗?

I am learning about the Git packfile and currently trying to reproduce (in Java) what I believe to be the SHA1 20-byte checksum for the entire packfile.我正在学习 Git 包文件,目前正在尝试(在 Java 中)重现我认为是整个包文件的 SHA1 20 字节校验和。 I take the byte array from, and including, the "PACK" 4-byte header to the end of the last packaged object's compressed data.我从“PACK”4 字节标头中获取字节数组,并将其包含到最后一个打包对象的压缩数据的末尾。 Everything I have read indicates that the next 20 bytes is the SHA1 checksum for the entire packfile.我读过的所有内容都表明接下来的 20 个字节是整个包文件的 SHA1 校验和。

The 20-byte checksum that is part of the byte array received from Git is: B910248BF9B63AC53595E3835CA57BDAF08DA830作为从 Git 收到的字节数组的一部分的 20 字节校验和是:B910248BF9B63AC53595E3835CA57BDAF08DA830

I use the following to calculate my own SHA1 checksum:我使用以下内容来计算我自己的 SHA1 校验和:
crypt = MessageDigest.getInstance("SHA-1");
crypt.reset();
crypt.update(testData);
byte [] result = crypt.digest();

My result ends up as: B910248BF9B63AC53595E3835CA57BDAF08DA813我的结果最终为:B910248BF9B63AC53595E3835CA57BDAF08DA813

I am baffled at how only the last byte of my result can be different from Git's (if I am using the correct part of the byte stream).我对结果的最后一个字节与 Git 的不同(如果我使用的是字节流的正确部分)感到困惑。 If the only problem was the range of data passed to digest() then the entire calculated checksum would most likely look different.如果唯一的问题是传递给digest() 的数据范围,那么整个计算的校验和很可能看起来不同。

Any ideas?有任何想法吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM