Example #1
0
        public static BaseEncryptor GetEncryptor(Encryptor encryptor)
        {
            BaseEncryptor cryptoProvider = null;

            if (encryptor == Encryptor.Aes)
            {
                if (rijndaelEncryptor == null)
                {
                    rijndaelEncryptor = new RijndaelEncryptor();
                }
                cryptoProvider = rijndaelEncryptor;
            }

            if (encryptor == Encryptor.Des)
            {
                if (dataEncryptor == null)
                {
                    dataEncryptor = new DataEncryptor();
                }
                cryptoProvider = dataEncryptor;
            }

            if (encryptor == Encryptor.Hash)
            {
                if (hashEncryptor == null)
                {
                    hashEncryptor = new HashEncryptor();
                }
                cryptoProvider = hashEncryptor;
            }

            return(cryptoProvider);
        }
Example #2
0
        public void ValidateTest()
        {
            string        message   = "XphteR";
            HashEncryptor encryptor = new HashEncryptor(Encoding.UTF8, new SHA256Managed());

            Assert.IsTrue(encryptor.Validate(message, encryptor.Encrypt(message)));
        }
Example #3
0
        public async Task <IdentityResult> CreateAsync(User user, CancellationToken cancellationToken)
        {
            user.SecurityStamp = Guid.NewGuid().ToString().ToLower().Replace("-", "");
            user.PasswordHash  = HashEncryptor.HmacSha1(user.SecurityStamp, user.PasswordHash);
            await db.Users.AddAsync(user);

            await db.SaveChangesAsync();

            return(IdentityResult.Success);
        }
Example #4
0
 public string HashPassword(User user, string password)
 {
     return(HashEncryptor.HmacSha1(user.SecurityStamp, password));
 }