Esempio n. 1
0
        private ICryptoService getCryptoService()
        {
            var size           = 128;
            var _keyGenerator  = new UserKeyGenerator(new RandomKeyGenerator(), size);
            var encryptService = new CryptoService(_keyGenerator, (x) => new DefaultHmacProvider(x));

            return(encryptService);
        }
Esempio n. 2
0
        public void SetUp()
        {
            DsaParametersGenerator paramGen = new DsaParametersGenerator();

            _dsaParameters = paramGen.GenerateParameters(1024, 160, 160);
            _dsaParameters.HashFunction = new Hasher(Hasher.HashImplementation.Sha1);

            UserKeyGenerator keyGen = new UserKeyGenerator(_dsaParameters);

            _keyPair = keyGen.GenerateKeyPair();

            _dsaAlgorithm = new DsaAlgorithm(_dsaParameters);
        }
Esempio n. 3
0
        public void execute_givenAPassword_GenerateEncryptedPasswordAndKey()
        {
            Func <IUnitOfWork> _uow;
            var _repository = userRepositoryCommands(out _uow);

            var _userTest = Builder <User> .CreateNew().Build();

            var _passwordUser = _userTest.Password;
            var size          = 128;
            var _keyGenerator = new UserKeyGenerator(new RandomKeyGenerator(), size);


            var encryptService = new CryptoService(_keyGenerator, (x) => new DefaultHmacProvider(x));

            var passwordEncrypted = encryptService.getEncryptedText(_passwordUser);
            var userKey           = _keyGenerator.getKey();

            var command = new CommandInsertUser(encryptService, _repository, _uow);

            command.execute(_userTest);

            Mock.Get(_repository).Verify(x => x.save(It.Is <User>(z => z.Password == passwordEncrypted &&
                                                                  z.UserKey == userKey)));
        }