public void Should_ReturnCiphertext_ForGivenString()
        {
            var password = "******";

            var encrypted = _aes256Encryptor.Encrypt(password);

            Assert.NotNull(encrypted);
            Assert.NotEqual(password, encrypted);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates an instance of encryption adapter.
        /// </summary>
        /// <param name="encryptor">The data encryptor, cannot be null.</param>
        /// <param name="key">The key of the cipher, it may have been used as extra entropy, cannot be null but can be empty.</param>
        /// <param name="data">The data to encrypt in a cipher, cannot be null but can be empty.</param>
        /// <returns>The encryption adapter, cannot be null.</returns>
        /// <exception cref="ArgumentNullException">The provider, key or data argument is null.</exception>
        /// <exception cref="CryptographicException">The encryption operation failed.</exception>
        public static IEncryptionAdapter CreateAdapter(IDataEncryptor encryptor, string key, byte[] data)
        {
            if (encryptor == null)
            {
                throw new ArgumentNullException("encryptor");
            }

            if (key == null)
            {
                throw new ArgumentNullException("key");
            }

            if (data == null)
            {
                throw new ArgumentNullException("data", string.Format(CultureInfo.InvariantCulture, "Object cannot be null for key {0}", key));
            }

            return(new EncryptionAdapter(encryptor.Encrypt(key, data)));
        }
        public async Task Upsert(PaymentRecord paymentRecord)
        {
            try
            {
                if (paymentRecord.PaymentStatus == PaymentStatus.Pending)
                {
                    paymentRecord.CardNumber = _dataEncryptor.Encrypt(paymentRecord.CardNumber);

                    _context.Payments.Add(paymentRecord);
                }
                else
                {
                    _context.Payments.Update(paymentRecord);
                }

                await _context.SaveChangesAsync();
            }
            catch (Exception exception)
            {
                _logger.LogError(exception.ToString());

                throw new PaymentRepositoryException(exception.Message);
            }
        }