Example #1
0
        static void PerformOneTest(string inputFilePath)
        {
            string fileName = Path.GetFileName(inputFilePath);

            byte[]        actual    = new JsonCanonicalizer(ArrayUtil.ReadFile(inputFilePath)).GetEncodedUTF8();
            byte[]        expected  = ArrayUtil.ReadFile(Path.Combine(Path.Combine(testData, "output"), fileName));
            StringBuilder utf8InHex = new StringBuilder("\nFile: ");

            utf8InHex.Append(fileName).Append('\n');
            int  byteCount = 0;
            bool next      = false;

            foreach (byte b in actual)
            {
                if (byteCount++ % 32 == 0)
                {
                    utf8InHex.Append('\n');
                    next = false;
                }
                if (next)
                {
                    utf8InHex.Append(' ');
                }
                next = true;
                utf8InHex.Append(((int)b).ToString("x02"));
            }
            Console.WriteLine(utf8InHex.Append('\n').ToString());
            if (!actual.SequenceEqual(expected))
            {
                Console.WriteLine("FAILED:\n" + new UTF8Encoding().GetString(actual));
            }
        }
Example #2
0
        protected override IVerifyData CreateVerifyData(JObject proof, ProofOptions options)
        {
            var documentCopy = options.Input.DeepClone();
            var proofCopy    = proof.DeepClone();

            proofCopy.Remove("signatureValue");
            documentCopy["proof"] = proofCopy;

            var canonicalizer = new JsonCanonicalizer(documentCopy.ToString())
                                .GetEncodedUTF8();
            var hashed = SHA256.Create().ComputeHash(canonicalizer);

            return((ByteArray)hashed);
        }
Example #3
0
        public static byte[] GetCanonicalizedInputBytes(string payload, string header)
        {
            // Json Canonicalization of JSON data needs to be done as we separate the signature from the payload
            // First Canonicalization of payload and extract its byte data
            JsonCanonicalizer canonicalizerPayload = new JsonCanonicalizer(payload);

            byte[] canonicalizedPayload = canonicalizerPayload.GetEncodedUTF8();

            // Next Canonicalization of the header part and extract its byte data
            JsonCanonicalizer canonicalizerHeader = new JsonCanonicalizer(header);

            byte[] canonicalizedHeader = canonicalizerHeader.GetEncodedUTF8();

            // Create a new byte array with the combination of the payload and the header
            byte[] canonicalizedFinalData = new byte[canonicalizedHeader.Length + canonicalizedPayload.Length];

            // Copy the header and payload into the final array
            Array.Copy(canonicalizedHeader, 0, canonicalizedFinalData, 0, canonicalizedHeader.Length);
            Array.Copy(canonicalizedPayload, 0, canonicalizedFinalData, canonicalizedHeader.Length, canonicalizedPayload.Length);

            return(canonicalizedFinalData);
        }