Exemple #1
0
        public ActionResult Login(LoginModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _accountRepository.GetUser(model.Name, _cryptor.Encrypt(model.Password));
                if (user != null)
                {
                    FormsAuthentication.SetAuthCookie(model.Name, true);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Пользователя с таким логином и паролем нет");
                }
            }

            return(View("Index"));//return View("Index",model)
        }
Exemple #2
0
        /// <summary>
        /// Encrpyts the unlocked content with the key of the assigned safe.
        /// </summary>
        /// <param name="unlockedContent">Content to encrypt.</param>
        /// <returns>Encrypted content.</returns>
        public string Lock(string unlockedContent)
        {
            string    encryptionAlgorithm = _settingsService.LoadSettingsOrDefault().SelectedEncryptionAlgorithm;
            SafeModel safe = _safes.FindById(Model.SafeId);

            byte[] binaryContent = CryptoUtils.StringToBytes(unlockedContent);
            byte[] lockedContent = _cryptor.Encrypt(binaryContent, safe.Key, encryptionAlgorithm, null);
            return(CryptoUtils.BytesToBase64String(lockedContent));
        }
        public async Task CreateNewMessage(MessageModel messageModel)
        {
            messageModel.ToLongTimeString = DateTime.Now.ToLongTimeString();

            ICryptor cryptor = CryptorFactory.CreateInstance(messageModel.CryptorType);

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

            await Clients.All.SendAsync("GetEncryptNewMessage", messageModel);
        }
 public (byte[] data, uint len) Encrypt(byte[] data, uint len)
 {
     // await encLock.WaitAsync();
     try
     {
         // Reserve for iv
         var outArr = new byte[len + 16];
         var outLen = cryptor.Encrypt(data, len, outArr);
         return(outArr, (uint)outLen);
     }
     finally
     {
         // encLock.Release();
     }
 }
        /// <summary>
        /// Encrypt input data using the cryptor. Will be used to send Shadowsocks requests.
        /// </summary>
        /// <param name="data">Input data.</param>
        /// <param name="outData">Output data. Must have enough capacity to hold encrypted data and any additional data.</param>
        /// <param name="cryptor">The cryptor to used. A null value indicates that the connection-wide cryptor should be used.</param>
        /// <returns>The length of <paramref name="outData"/> used.</returns>
        public virtual unsafe uint Encrypt(ReadOnlySpan <byte> data, Span <byte> outData, ICryptor cryptor = null)
        {
            if (cryptor == null)
            {
                cryptor = this.cryptor;
            }

            fixed(byte *dataPtr = &data.GetPinnableReference(), outDataPtr = &outData.GetPinnableReference())
            {
                // Reserve for iv
                var outLen = cryptor.Encrypt((ulong)dataPtr, (uint)data.Length, (ulong)outDataPtr, (uint)outData.Length);

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

#pragma warning restore IDE0004
            }
        }
Exemple #6
0
        public int Enc(
            [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.Encrypt(value));

            return(0);
        }
 private PaymentEntity BuildPaymentEntity(PaymentRequestModel request, MerchantAcquirerEntity merchantAcquirer)
 {
     return(new PaymentEntity
     {
         PaymentId = Guid.NewGuid().ToString(),
         MerchantId = merchantAcquirer.MerchantId,
         MerchantName = merchantAcquirer.MerchantName,
         AcquirerId = merchantAcquirer.AcquirerId,
         AcquirerName = merchantAcquirer.AcquirerName,
         TrackId = request.TrackId,
         Status = Constants.PendingStatus,
         Amount = request.Amount,
         Currency = request.Currency,
         CardNumber = _cryptor.Encrypt(request.Card.Number),
         ExpiryMonth = request.Card.ExpiryMonth,
         ExpiryYear = request.Card.ExpiryYear,
         CardholderName = request.Card.Name,
         PaymentTime = DateTime.UtcNow
     });
 }
Exemple #8
0
 /// <summary>
 /// 獲取打包數據並加密
 /// </summary>
 /// <returns></returns>
 public byte[] GetEncryptedBytes(ICryptor cryptor, byte[] cryptKey)
 {
     return(cryptor.Encrypt(GetBytes(), cryptKey));
 }
Exemple #9
0
 public void PutEncryptedBytes(byte[] value, ICryptor cryptor, byte[] cryptKey,
                               byte prefixLength = 0, byte limitedLength = 0)
 {
     PutBytes(cryptor.Encrypt(value, cryptKey), prefixLength, limitedLength);
 }
Exemple #10
0
 public void PutEncryptedBytes(byte[] value, ICryptor cryptor, byte[] cryptKey)
 {
     WriteBytes(cryptor.Encrypt(value, cryptKey));
 }
Exemple #11
0
 public byte[] GetEncryptedBytes(bool prefixTlvCount, ICryptor cryptor, byte[] cryptKey)
 {
     return(cryptor.Encrypt(GetBytes(prefixTlvCount), cryptKey));
 }
 /// <summary>
 /// Embeds DWM within container.
 /// </summary>
 /// <param name="cryptor">Crypt algorithm.</param>
 /// <param name="embeder">Embeding algorithm.</param>
 /// <param name="message">Secret message.</param>
 /// <param name="key">Crypting key.</param>
 /// <param name="container">Container.</param>
 /// <param name="fileName">Container file name.</param>
 /// <returns>Saved file name at server.</returns>
 public static void EmbedDwm(ICryptor cryptor, IEmbeder embeder, string message, Key key, Container container)
 {
     Stream cryptedMessage = cryptor.Encrypt(StreamHelper.StringToStream(message), key);
     embeder.Embed(container, StreamHelper.StreamToBytesArray(cryptedMessage));
 }
Exemple #13
0
 public static string Encrypt(this string str, ICryptor cryptor)
 {
     return(cryptor.Encrypt(str));
 }
Exemple #14
0
 public void PutEncryptedBytes(byte[] value, ICryptor cryptor, byte[] cryptKey,
     Prefix prefixFlag = Prefix.None, byte limitedLength = 0)
 {
     PutBytes(cryptor.Encrypt(value, cryptKey), prefixFlag, limitedLength);
 }