由于清单 pass.json 字符串格式,.pkpass 创建失败?

.pkpass create fail because of manifest pass.json string format?

这是一个很奇怪的问题。

我用C#创建了一个pass.json并保存到memoryStream中,运行正常。之后,我创建了 manifest.json SHA1 数据,其中包括 pass.json,manifest.json 的字符串,它是完全正确的。

{"icon.png":     "9423bd00e2b01c59a3265c38b5062fac7da0752d",
 "icon@2x.png": "4d1db55bdaca70b685c013529a1c0dcbd7046524",
 "logo.png":     "ee5b053e63dbfe3b78378c15d163331d68a0ede8",
 "logo@2x.png": "2f9e3a55bded1163620719a4d6c1ad496ed40c17",
 "pass.json":    "fd68bf77757d3057263a9aca0e5110ddd933934a"}

生成 pkpass 作为我的phone后,无法打开。我将 pass.json SHA1 代码更改为 "fd68bf77757d3057263a9aca0e5110ddd933934a",但没有使用值来保存它,它有效

编码如下:

// This version run success
var strPass = JavascriptSerialize(details);
var sw = new StreamWriter(assetsFolder + @"pass.json");
sw.Write(strPass);
sw.Close();
manifest.passjson = GetSha1Hash(assetsFolder + manifest.GetAssetBoardingPass(libPkPass_object_boardingPass.JsonObjects.AssetTypes.passjson));

//manifest.passjson = "2f9e3a55bded1163620719a4d6c1ad496ed40c17"
// end

// This version run fail
var strPass = JavascriptSerialize(details);
MemoryStream stream = new MemoryStream();
StreamWriter writer = new StreamWriter(strPass);
writer.Write(s);
writer.Flush();
stream.Position = 0;
var a = GetSha1HashMemory(passStream);
    private static string GetSha1HashMemory(Stream passStream)
    {

        //var bs = new BufferedStream(passStream);
        using (SHA1Managed sha = new SHA1Managed())
        {
            byte[] checksum = sha.ComputeHash(passStream);
            string sendCheckSum = BitConverter.ToString(checksum)
                .Replace("-", string.Empty);
            return sendCheckSum.ToString().ToLower();
        }
    }
manifest.passjson = a;

//manifest.passjson = "2f9e3a55bded1163620719a4d6c1ad496ed40c17" (same data )
//end

这是怎么回事?????我可以找出任何字符串错误的问题。 pkpass 提供在 here (sendspace).

谁能告诉我哪里错了?

非常感谢!

两个错误:
ComputeHash(Stream)使用 Stream

ComputeHash(Stream) : ComputeHash stream 仅使用 System.IO.Stream,不使用 MemoryStream,改为 ComputeHash(bytes[]) 即可处理

using Stream:我尝试将流传递给其他函数,这不是一个很好的例子,流需要创建一个新流并且它可能会替换您计算机流中的一些字节。在这种情况下,我只需要调用这个函数就会打开一个新的,它会修复

                StringBuilder formatted;
                using (var sha1 = new SHA1Managed())
                {
                    //var bytePass = ReadFully(passStream);
                    var bytePass = passStream.ToArray();
                    var hash = sha1.ComputeHash(bytePass);
                    formatted = new StringBuilder(2 * hash.Length);
                    foreach (var b in hash)
                    {
                        formatted.AppendFormat("{0:X2}", b);
                    }
                }
                manifest.passjson = formatted.ToString().ToLower();