예제 #1
0
파일: Keygen.cs 프로젝트: labo89/nusdm
        public static string GenerateKey(string tid)
        {
            byte[] secret = DeriveSecret(-3, 10);

            byte[] munged = MungeTid(tid.Replace(" ", ""));

            byte[] hashed = GetHash(secret.Concat(munged).ToArray());

            string pass = "******";

            byte[] key;

            using (var pbkdf2 = new Rfc2898DeriveBytes(pass, hashed, 20, HashAlgorithmName.SHA1))
            {
                key = pbkdf2.GetBytes(16);
            }

            byte[] commonKey = HexToByteArray(FormatHexString(commonKeyNoWhitespace));



            // Initialization vector IV: https://en.wikipedia.org/wiki/Initialization_vector
            byte[] iv = HexToByteArray(FormatHexString(tid));

            Array.Resize(ref iv, 16);

            var crypto = new AesCryptographyService();

            var encrypted = crypto.Encrypt(key, commonKey, iv);

            return(BitConverter.ToString(encrypted).Replace("-", "").ToUpper());
        }
예제 #2
0
        public async Task <bool> SignIn(string username, string password)
        {
            try
            {
                var endpoint  = configuration.GetSection("Endpoints").GetSection("Identity").Value;
                var encrypter = new AesCryptographyService();
                using (var httpClient = new HttpClient())
                {
                    httpClient.BaseAddress = new Uri(endpoint);
                    var content = Json.CreateJsonContent(new UserModel
                    {
                        Email    = username,
                        Password = encrypter.Encrypt(password)
                    });

                    var response = await httpClient.PostAsync("/api/authentication/signin", content);

                    var result = await response.Content.ReadAsStringAsync();

                    response.EnsureSuccessStatusCode();

                    var model = Json.Deserialize <UserModel>(result);

                    memoryCache.CreateEntry(model.Email);
                    memoryCache.Set(model.Email, model, new MemoryCacheEntryOptions
                    {
                        SlidingExpiration = TimeSpan.FromMinutes(60)
                    });

                    return(true);
                }
            }
            catch (Exception ex)
            {
                logger.LogError(ex, $"Unable to authenticate {username}");
                return(false);
            }
        }
예제 #3
0
 public UnitOfWorkUser(ECraftContext context, AesCryptographyService crypto)
 {
     _context = context;
     _crypto  = crypto;
     UserRepo = new CryptoBaseRepository <User>(context, crypto);
 }
예제 #4
0
 public CryptoBaseRepository(ECraftContext context, AesCryptographyService crypto)
 {
     this.Context = context;
     this.dbSet   = context.Set <TEntity>();
     this._crypto = crypto;
 }