Пример #1
0
 static async Task EncryptCoreAsync(IEncryptor encryptor,
                                    byte[] plainBytes, string password, Stream outputStream)
 {
     using (var inputStream = new MemoryStream(plainBytes))
     {
         await encryptor.EncryptAsync(inputStream, password, outputStream);
     }
 }
Пример #2
0
        public async Task <User> AddUserAsync(User userModel)
        {
            var user = await repository.GetUserByEmailAsync(userModel.Email);

            if (user != null)
            {
                throw new DuplicateNameException("email already exists in the system.");
            }
            var userRole = await repository.GetUserRoleByNameAsync(adminRole);

            if (userRole == null)
            {
                throw new KeyNotFoundException("The admin role was not configured.");
            }
            userModel.Password = await encryptor.EncryptAsync(configuration.DefaultPassword);

            userModel.RoleId = userRole.Id;
            user             = await repository.AddUserAsync(userModel);

            return(user);
        }
Пример #3
0
        static async Task <byte[]> EncryptCoreAsync(IEncryptor encryptor,
                                                    byte[] plainBytes, string password)
        {
            using (var outputStream = new MemoryStream())
            {
                using (var inputStream = new MemoryStream(plainBytes))
                {
                    await encryptor.EncryptAsync(inputStream, password, outputStream);
                }

                byte[] result = outputStream.ToArray();
                return(result);
            }
        }
Пример #4
0
        public async Task <Session> LoginAsync(LoginModel login)
        {
            login.Password = await encryptor.EncryptAsync(login.Password);

            var user = await repository.GetUserAsync(login);

            if (user == null)
            {
                throw new InvalidCredentialException("Invalid credentials");
            }
            var session = await repository.GetSessionAsync(user);

            if (session == null)
            {
                session = await repository.CreateSessionAsync(user);
            }
            return(session);
        }
Пример #5
0
 internal CryptoStorage()
 {
     encryptionTransformation = (src, dest) => encryptor.EncryptAsync(src, dest, accessKey);
     decryptionTransformation = (src, dest) => encryptor.DecryptAsync(src, dest, accessKey);
 }