Beispiel #1
0
        public void Write(Stream stream, AndroidApkSigningTool.HashAlgorithmInfo hashAlgorithmInfo)
        {
            using (var manifestHasher = hashAlgorithmInfo.HashAlgorithmFactory())
            {
                manifestHasher.Initialize();

                MainSection.Write(stream, manifestHasher, hashAlgorithmInfo);

                foreach (var section in AdditionalSections.Values)
                {
                    section.Write(stream, manifestHasher, hashAlgorithmInfo);
                }

                //stream.Write(NewLineBytes,0, NewLineBytes.Length);
                manifestHasher.TransformFinalBlock(new byte[0], 0, 0);
                Digest = Convert.ToBase64String(manifestHasher.Hash);
            }
        }
        public void Write(Stream target, HashAlgorithm manifestHasher, AndroidApkSigningTool.HashAlgorithmInfo hashAlgorithmInfo)
        {
            using (var sectionHasher = hashAlgorithmInfo.HashAlgorithmFactory())
            {
                sectionHasher.Initialize();

                byte[] writtenData = target.WriteManifestLine($"{Name}: {Value}");
                manifestHasher.TransformBlock(writtenData, 0, writtenData.Length, null, 0);
                sectionHasher.TransformBlock(writtenData, 0, writtenData.Length, null, 0);

                foreach (var entry in this)
                {
                    writtenData = target.WriteManifestLine($"{entry.Key}: {entry.Value}");
                    manifestHasher.TransformBlock(writtenData, 0, writtenData.Length, null, 0);
                    sectionHasher.TransformBlock(writtenData, 0, writtenData.Length, null, 0);
                }

                target.Write(Manifest.NewLineBytes, 0, Manifest.NewLineBytes.Length);
                manifestHasher.TransformFinalBlock(Manifest.NewLineBytes, 0, Manifest.NewLineBytes.Length);
                sectionHasher.TransformFinalBlock(Manifest.NewLineBytes, 0, Manifest.NewLineBytes.Length);
                Digest = Convert.ToBase64String(sectionHasher.Hash);
            }
        }