Exemple #1
0
        public void TestHashPassword()
        {
            const string password      = "******";
            const string rightPassword = "******";
            const string wrongPassword = "******";

            byte[] salt             = PBKDF2Impl.GenerateSalt();
            byte[] encrypedPassword = PBKDF2Impl.HashPassword(Encoding.UTF8.GetBytes(password), salt);

            byte[] encrypedRightPassword = PBKDF2Impl.HashPassword(Encoding.UTF8.GetBytes(rightPassword), salt);
            byte[] encrypedWrongPassword = PBKDF2Impl.HashPassword(Encoding.UTF8.GetBytes(wrongPassword), salt);

            Assert.IsTrue(AbstractSecureCompareBase.Compare(encrypedPassword, encrypedRightPassword));
            Assert.IsFalse(AbstractSecureCompareBase.Compare(encrypedPassword, encrypedWrongPassword));
        }
        public void Insert()
        {
            List <Contact> contacts = _dataAccess.GetAll <Contact>();

            Assert.IsTrue(contacts.Count == 0);

            List <MasterLogin> materLogins = _dataAccess.GetAll <MasterLogin>();

            Assert.IsTrue(materLogins.Count == 0);

            var hybridEncrypter = new HybridRsaAes();

            hybridEncrypter.AssignNewRSAKeys();

            var contact = new Contact
            {
                Name      = "Marcel",
                PublicKey = hybridEncrypter.GetPublicRSAKey()
            };

            _dataAccess.Insert(contact);

            contacts = _dataAccess.GetAll <Contact>();
            Assert.IsTrue(contacts.Count == 1);

            var salt = PBKDF2Impl.GenerateSalt();

            hybridEncrypter = new HybridRsaAes();
            hybridEncrypter.AssignNewRSAKeys();

            var materLogin = new MasterLogin
            {
                Name       = "MasterMan",
                Password   = PBKDF2Impl.HashPassword(Encoding.UTF8.GetBytes("password123"), salt),
                Salt       = salt,
                PrivateKey = hybridEncrypter.GetPrivateRSAKeyAsXml(),
                PublicKey  = hybridEncrypter.GetPublicRSAKey()
            };

            _dataAccess.Insert(materLogin);

            materLogins = _dataAccess.GetAll <MasterLogin>();
            Assert.IsTrue(materLogins.Count == 1);
        }
Exemple #3
0
 public byte[] HashPassword(string plainPassword, byte[] salt)
 {
     _logger.Info("hash password");
     return(PBKDF2Impl.HashPassword(Encoding.UTF8.GetBytes(plainPassword), salt));
 }
Exemple #4
0
 public byte[] GenerateSalt()
 {
     _logger.Info("generate salt");
     return(PBKDF2Impl.GenerateSalt());
 }