Ejemplo n.º 1
0
        private static string Decrypt(string p_Value)
        {
            var    target         = new CipherEngine();
            string decriptedValue = target.Decrypt(p_Value);

            return(decriptedValue);
        }
Ejemplo n.º 2
0
        internal void DecodeAuthToken()
        {
            var           target         = new CipherEngine();
            List <string> decriptedValue = target.Decrypt(this.T).Split(',').ToList();

            this.SID = decriptedValue.First();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Measure cipher performance in MB/s
        /// </summary>
        /// <param name="cipher">Cipher instance</param>
        /// <returns>Speed in MB/s</returns>
        public static string SpeedTest(ICipherAlgorithm cipher)
        {
            const int SAMPLE_SIZE_KB = 4;
            const int TEST_CYCLES    = 1024;

            byte[] plainText = new byte[SAMPLE_SIZE_KB * 1024];
            byte[] key       = new byte[cipher.KeyLength];
            byte[] iv        = new byte[cipher.BlockSize];

            Random rng = new Random();

            rng.NextBytes(plainText);
            rng.NextBytes(key);
            rng.NextBytes(iv);

            CipherEngine engine       = new CipherEngine(cipher);
            Stream       cipherStream = engine.EncryptStream(new MemoryStream(), key, iv);

            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int c = 0; c < TEST_CYCLES; c++)
            {
                using (MemoryStream plainTextStream = new MemoryStream(plainText)) {
                    plainTextStream.WriteTo(cipherStream);
                }
            }
            sw.Stop();

            return(String.Format("{0} = {1:0.00} KB/s", cipher.Name, (float)((1000.0 * SAMPLE_SIZE_KB * TEST_CYCLES) / (sw.ElapsedMilliseconds * 1.0))));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Used to generate an X509Certificate.
        /// </summary>
        public X509CertificateGenerator()
        {
            System.Random r = new System.Random();
            CipherEngine = CipherEngine.RSACryptoServiceProvider;

            KeySize       = 2048;
            SignatureBits = 256;
            SerialNumber  = ((long)r.Next() << 31) ^ r.Next();
            Issuer        = Guid.NewGuid().ToString("N");
            Subject       = Issuer;
            NotBefore     = new DateTime(DateTime.UtcNow.Date.AddDays(-7).Year, 1, 1, 0, 0, 0, DateTimeKind.Utc);
            NotAfter      = NotBefore.AddYears(10);
        }
Ejemplo n.º 5
0
        private string GetAuthorizationToken(GATRequest p_Data, Guid p_Guid)
        {
            if (!CachingLayer.IPThrottle(p_Data.IPAddress))
            {
                throw new AccessViolationException("Throtteling was defined");
            }
            var target = new CipherEngine();
            //long p_SIDRandomNumber = new Random().Next(int.MinValue, int.MaxValue);
            string p_DataToEncrypt = string.Join(",", p_Guid, p_Data.CallingPage, ConfigurationManager.AppSettings["AppID"], p_Data.IPAddress, /* p_SIDRandomNumber,*/ DateTime.UtcNow.Ticks);
            string SIDKey          = target.Encrypt(p_DataToEncrypt);

            CachingLayer.Insert(SIDKey, p_Guid.ToString());
            return(SIDKey);
        }
 private bool Authorize(HttpActionContext actionContext)
 {
     try
     {
         var    request = actionContext.Request.Content.ReadAsStreamAsync().Result;
         string rawRequest;
         using (var stream = new StreamReader(actionContext.Request.Content.ReadAsStreamAsync().Result))
         {
             stream.BaseStream.Position = 0;
             rawRequest = stream.ReadToEnd();
         }
         dynamic header = JsonConvert.DeserializeObject(rawRequest);
         /*string token = request.Params[_securityToken];*/
         CipherEngine crypto = new CipherEngine();
         var          temp   = crypto.Decrypt(header.T.Value).Split(',');
         string       ip     = temp [3] ?? SecurityFacadeManager.GetIP(actionContext.Request);
         return(SecurityFacade.IsTokenValid(header.TN.Value, ip, header.UA.Value));
     }
     catch (Exception)
     {
         return(false);
     }
 }
Ejemplo n.º 7
0
 public CBCBlockCipher(int keybits, CipherEngine engine)
 {
     key         = new byte[keybits / 8];
     this.engine = engine;
 }