コード例 #1
0
        public static byte[] UnbundleKeyFetchResponse(string key, string bundleHex)
        {
            byte[] bundle    = BinaryHelper.FromHexString(bundleHex); // bundle
            byte[] bundleKey = BinaryHelper.FromHexString(key);       // key

            BundleKeys keys = DeriveBundleKeys(bundleKey, "account/keys");

            byte[] cipherText   = bundle.Take(64).ToArray();
            byte[] expectedHmac = bundle.Skip(bundle.Length - 32).Take(32).ToArray();

            using (var hmac = new HMACSHA256(keys.HmacKey))
            {
                if (!BinaryHelper.AreEqual(expectedHmac, hmac.ComputeHash(cipherText)))
                {
                    throw new Exception("Bad HMac.");
                }
            }

            byte[] keyAWrapB = BinaryHelper.Xor(bundle.Take(64).ToArray(), keys.XorKey);
            byte[] kA        = keyAWrapB.Take(32).ToArray();
            byte[] wrapKB    = keyAWrapB.Skip(32).ToArray();

            return(wrapKB);
        }