Exemple #1
0
        private static string HexToBase64(string hex)
        {
            int num = hex.Length / 2;

            byte[] array = new byte[num];
            for (int i = 0; i < num; i++)
            {
                array[i] = (byte)((CustomAntiForgeryDataSerializer.HexValue(hex[i * 2]) << 4) + CustomAntiForgeryDataSerializer.HexValue(hex[i * 2 + 1]));
            }
            return(Convert.ToBase64String(array));
        }
Exemple #2
0
        private static string Base64ToHex(string base64)
        {
            StringBuilder stringBuilder = new StringBuilder(base64.Length * 4);

            byte[] array = Convert.FromBase64String(base64);
            for (int i = 0; i < array.Length; i++)
            {
                byte b = array[i];
                stringBuilder.Append(CustomAntiForgeryDataSerializer.HexDigit(b >> 4));
                stringBuilder.Append(CustomAntiForgeryDataSerializer.HexDigit((int)(b & 15)));
            }
            return(stringBuilder.ToString());
        }
Exemple #3
0
        public virtual CustomAntiForgeryData Deserialize(string serializedToken)
        {
            if (string.IsNullOrEmpty(serializedToken))
            {
                throw new ArgumentException(CustomAntiForgeryResources.Common_NullOrEmpty, "serializedToken");
            }
            CustomAntiForgeryData result;

            try
            {
                using (MemoryStream memoryStream = new MemoryStream(this.Decoder(serializedToken)))
                {
                    using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                    {
                        result = new CustomAntiForgeryData
                        {
                            Salt         = binaryReader.ReadString(),
                            Value        = binaryReader.ReadString(),
                            CreationDate = new DateTime(binaryReader.ReadInt64()),
                            Username     = binaryReader.ReadString()
                        };
                    }
                }
            }
            catch (Exception innerException)
            {
                if (CustomAntiForgeryConfig.DebugMode)
                {
                    CM.Web.AntiForgery.Custom.Logger.Exception(CustomAntiForgeryDataSerializer.CreateValidationException(innerException));
                    result = null;
                }
                else
                {
                    throw CustomAntiForgeryDataSerializer.CreateValidationException(innerException);
                }
            }
            return(result);
        }
Exemple #4
0
 public CustomAntiForgeryWorker()
 {
     this.Serializer = new CustomAntiForgeryDataSerializer();
 }