Пример #1
0
        public void EnhancedMemoryStream_Int64()
        {
            var es = new EnhancedMemoryStream();

            es.WriteInt64(0);
            es.WriteInt64(65121);
            es.WriteInt64(0x12345678);
            es.WriteInt64((((long)0x12345678) << 32) | (long)0xaabbccddee);

            es.Seek(0, SeekOrigin.Begin);

            Assert.AreEqual(0, es.ReadInt64());
            Assert.AreEqual(65121, es.ReadInt64());
            Assert.AreEqual(0x12345678, es.ReadInt64());
            Assert.AreEqual((((long)0x12345678) << 32) | (long)0xaabbccddee, es.ReadInt64());
        }
Пример #2
0
        /// <summary>
        /// Renders the instance into a string suitable for using as an HTTP cookie.
        /// </summary>
        /// <returns>The cookie string.</returns>
        public override string ToString()
        {
            using (var ms = new EnhancedMemoryStream())
            {
                ms.WriteInt16(Magic);
                ms.WriteInt64(IssueDateUtc.Ticks);
                ms.WriteBytesNoLen(ID.ToByteArray());

                return(Convert.ToBase64String(ms.GetBuffer(), 0, (int)ms.Length));
            }
        }
Пример #3
0
        /// <summary>
        /// Generates a request signature using a shared <see cref="SymmetricKey" />
        /// for request arguments as well as the current time.
        /// </summary>
        /// <param name="sharedKey">The shared <see cref="SymmetricKey" />.</param>
        /// <param name="args">The request argument collection.</param>
        /// <returns>The base-64 encoded signature.</returns>
        public static string Generate(SymmetricKey sharedKey, ArgCollection args)
        {
            using (var ms = new EnhancedMemoryStream(512))
            {
                ms.WriteBytesNoLen(Crypto.GetSalt8());
                ms.WriteInt32(Magic);
                ms.WriteInt64(DateTime.UtcNow.Ticks);
                ms.WriteBytesNoLen(ComputeHash(args, null));

                return(Convert.ToBase64String(Crypto.Encrypt(ms.ToArray(), sharedKey)));
            }
        }