public static string ExtractDwm(IEmbeder embeder, ICryptor cryptor, Key key, Container container)
        {
            byte[] byteMessage = embeder.Extract(container, key);
            Stream message = cryptor.Decrypt(StreamHelper.BytesToStream(byteMessage), key);

            return StreamHelper.StreamToString(message);
        }
        public async Task Decrypt(MessageModel messageModel)
        {
            ICryptor cryptor = CryptorFactory.CreateInstance(messageModel.CryptorType);

            messageModel.Message = await cryptor.Decrypt(messageModel);

            await Clients.Caller.SendAsync("GetDecryptNewMessage", messageModel);
        }
        public override void Load(Stream stream)
        {
            base.Load(stream);

            var encryptedItems = Data.Where(x => x.Key.EndsWith(".Encrypted",
                                                                StringComparison.CurrentCultureIgnoreCase));

            foreach (var item in encryptedItems)
            {
                decrypted.Add(item.Key.Replace(".Encrypted", ""), cryptor.Decrypt(item.Value));
            }
        }
Example #4
0
        /// <summary>
        /// Decrypts the note, if the belonging safe is open.
        /// </summary>
        /// <returns>Decrypted note content, or null if the safe is closed.</returns>
        private string UnlockIfSafeOpen(string lockedContent)
        {
            SafeModel safe = _safes.FindById(Model.SafeId);

            if ((safe != null) && safe.IsOpen)
            {
                byte[] binaryContent   = CryptoUtils.Base64StringToBytes(lockedContent);
                byte[] unlockedContent = _cryptor.Decrypt(binaryContent, safe.Key);
                return(CryptoUtils.BytesToString(unlockedContent));
            }
            return(null);
        }
 public Memory <byte> Decrypt(byte[] data, uint len)
 {
     // await decLock.WaitAsync();
     try
     {
         var outLen = cryptor.Decrypt(data, len, decryptBuf);
         return(decryptBuf.AsMemory(0, (int)outLen));
     }
     finally
     {
         // decLock.Release();
     }
 }
        public unsafe virtual uint Decrypt(ReadOnlySpan <byte> data, Span <byte> outData, ICryptor cryptor = null)
        {
            if (cryptor == null)
            {
                cryptor = this.cryptor;
            }

            fixed(byte *dataPtr = &data.GetPinnableReference(), outDataPtr = &outData.GetPinnableReference())
            {
                var outLen = cryptor.Decrypt((ulong)dataPtr, (uint)data.Length, (ulong)outDataPtr, (uint)outData.Length);

#pragma warning disable IDE0004
                return((uint)outLen);

#pragma warning restore IDE0004
            }
        }
Example #7
0
        public int Dec(
            [Argument] string value,
            [Option('k')] string key,
            [Option('v')] string iv,
            [Option('a')][Algorithms] string algorithms = DefaultAlgorithms
            )
        {
            ICryptor cryptor = algorithms switch
            {
                nameof(SupportAlgorithms.TripleDES) => new TripleDESCryptor(key, iv),
                nameof(SupportAlgorithms.DES) => new DESCryptor(key, iv),
                _ => throw new ArgumentException()
            };

            Console.WriteLine(cryptor.Decrypt(value));

            return(0);
        }
Example #8
0
        /// <summary>
        /// Authenticates the user login. This gets the user from the repository, decrypts
        /// the stored password and determines if the un-encrypted password in passwordGuess
        /// is the same as the un-encrypted password from the user retrieved in the
        /// repository.
        /// </summary>
        public static async Task <U> Authenticate <U>(string username, string passwordGuess,
                                                      IGateKeeperUserRepository <U> userRepository, ICryptor cryptor,
                                                      GateKeeperConfig gateKeeperConfig) where U : IUser
        {
            U user = await userRepository.GetByUsername(username);

            if (user == null)
            {
                throw new AuthenticationException(AuthenticationException.REASON_USER_NOT_FOUND);
            }
            string realPassword = cryptor.Decrypt(user.Password, gateKeeperConfig.EncryptionKey, gateKeeperConfig.Salt);

            if (passwordGuess != realPassword)
            {
                throw new AuthenticationException(AuthenticationException.REASON_WRONG_PASSWORD);
            }
            return(user);
        }
 private bool TryDecryptRepositoryWithTransfercode(ICryptor decryptor, byte[] binaryCloudRepository, string transferCode, out byte[] decryptedRepository)
 {
     try
     {
         decryptedRepository = decryptor.Decrypt(binaryCloudRepository, CryptoUtils.StringToSecureString(transferCode));
         return(true);
     }
     catch (CryptoExceptionInvalidCipherFormat)
     {
         // If the downloaded repository is invalid, this is serious and we should not continue
         throw;
     }
     catch (CryptoUnsupportedRevisionException)
     {
         throw;
     }
     catch (Exception)
     {
         // Could not decrypt with this transfercode
         decryptedRepository = null;
         return(false);
     }
 }
Example #10
0
        public async Task <PaymentResponseModel> GetByIdAsync(Guid paymentId, MerchantModel merchant)
        {
            Guard.IsNotNull(paymentId, nameof(paymentId));
            _merchantModelValidator.ValidateAndThrow(merchant);

            var payment = await _paymentRepository.GetByIdAsync(paymentId);

            if (payment == null)
            {
                throw new ObjectNotFoundException($"No payment with id '{ paymentId } was found.'");
            }

            // This check should normally return a Not Found exception for security purposes. Unauthorized used for testing purposes only.
            if (payment.MerchantId != merchant.Id)
            {
                throw new UnauthorizedException($"Merchant is not authorised to retrieve this payment.");
            }

            var response = _mapper.Map <PaymentResponseModel>(payment);

            response.Card.Number = MaskHelper.MaskCardNumber(_cryptor.Decrypt(response.Card.Number));

            return(response);
        }
Example #11
0
 public static string Decrypt(this string str, ICryptor cryptor)
 {
     return(cryptor.Decrypt(str));
 }
Example #12
0
 public Packet(byte[] data, ICryptor cryptor, byte[] cryptKey)
     : base()
 {
     buffer = cryptor.Decrypt(data, cryptKey);
     bufferLength = (uint)buffer.Length;
 }
Example #13
0
 public StreamReader TakeRemainDecrypedBytes(out byte[] value, ICryptor cryptor, byte[] key)
 {
     TakeRemainBytes(out var data);
     value = cryptor.Decrypt(data, key);
     return(this);
 }