public ActionResult PaymentIndex() { // Get total price var cart = ShoppingCart.GetCart(this.HttpContext); var cartTotal = cart.GetTotal(); // Get total Cart Items var cartItemsWithID = cart.GetCartItems().ToList(); // Get current Art creator from cart var artsCreator = ""; foreach (var item in cartItemsWithID) { artsCreator = item.Arts.Creator; } // Get eth adres of artCreator var userCreator = _context.Users.FirstOrDefault(a => a.UserName == artsCreator) .CryptoWallet; var result = new CryptoViewModel { TotalAmount = cartTotal, SendEthToAdress = userCreator, }; return(View(result)); }
public static CryptoViewModel <JObject> DecryptStringFromBytes_Aes(string cipherText, string keyString, string iv) { CryptoViewModel <JObject> result = new CryptoViewModel <JObject>() { Base64Key = keyString, Base64IV = iv }; var Key = Convert.FromBase64String(keyString); var IV = Convert.FromBase64String(iv); // Check arguments. if (cipherText == null || cipherText.Length <= 0) { throw new ArgumentNullException("cipherText"); } if (Key == null || Key.Length <= 0) { throw new ArgumentNullException("Key"); } if (IV == null || IV.Length <= 0) { throw new ArgumentNullException("IV"); } // Declare the string used to hold // the decrypted text. string plaintext = null; var fullCipher = Convert.FromBase64String(cipherText); // Create an Aes object // with the specified key and IV. using (AesManaged aesAlg = new AesManaged()) { aesAlg.Mode = CipherMode.ECB; aesAlg.Padding = PaddingMode.PKCS7; aesAlg.Key = Key; aesAlg.IV = IV; // Create a decryptor to perform the stream transform. ICryptoTransform decryptor = aesAlg.CreateDecryptor(aesAlg.Key, aesAlg.IV); // Create the streams used for decryption. using (MemoryStream msDecrypt = new MemoryStream(fullCipher)) { using (CryptoStream csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) { using (StreamReader srDecrypt = new StreamReader(csDecrypt)) { // Read the decrypted bytes from the decrypting stream // and place them in a string. plaintext = srDecrypt.ReadToEnd(); } } } } result.Data = JObject.Parse(plaintext); return(result); }
public async Task <IActionResult> UpdateCrypto([FromForm] CryptoViewModel cryptoToUpdate) { if (cryptoToUpdate.valueUSD != null) { cryptoToUpdate.valueBTC = (double.Parse(cryptoToUpdate.valueUSD) / 7000).ToString(); cryptoToUpdate.valueETH = (double.Parse(cryptoToUpdate.valueUSD) / 283).ToString(); } var result = await _cosmosStore.UpdateAsync(cryptoToUpdate); return(RedirectToAction("Index")); }
public static CryptoViewModel <string> EncryptStringToBytes_Aes(JObject plainText) { var result = new CryptoViewModel <string>(); //var Key = Convert.FromBase64String(keyString); //var IV = Convert.FromBase64String(iv); // Check arguments. if (plainText == null) { throw new ArgumentNullException("plainText"); } //if (Key == null || Key.Length <= 0) // throw new ArgumentNullException("Key"); //if (IV == null || IV.Length <= 0) // throw new ArgumentNullException("IV"); byte[] encrypted; // Create an Aes object // with the specified key and IV. using (AesManaged aesAlg = new AesManaged()) { aesAlg.Mode = CipherMode.ECB; aesAlg.Padding = PaddingMode.PKCS7; //aesAlg.Key = Key; //aesAlg.IV = IV; result.Base64Key = Convert.ToBase64String(aesAlg.Key); result.Base64IV = Convert.ToBase64String(aesAlg.IV); // Create an encryptor to perform the stream transform. ICryptoTransform encryptor = aesAlg.CreateEncryptor(aesAlg.Key, aesAlg.IV); // Create the streams used for encryption. using (MemoryStream msEncrypt = new MemoryStream()) { using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write)) { using (StreamWriter swEncrypt = new StreamWriter(csEncrypt)) { //Write all data to the stream. swEncrypt.Write(plainText); } encrypted = msEncrypt.ToArray(); } } } // Return the encrypted bytes from the memory stream. result.Data = Convert.ToBase64String(encrypted); return(result); }
public async Task <ActionResult> Deposit() { // Get current username var user = _context.Users.FirstOrDefault(c => c.UserName == User.Identity.Name); var web3 = new Web3(); // Get ETH private ETH adres of Sender if (user.Email == "*****@*****.**") { var account = new Account(staffmemberPrivateETH); //create an instance of Web3 using our account pointing to our nethereum testchain web3 = new Web3(account, web3Url); } else if (user.Email == "*****@*****.**") { var account = new Account(studentPrivateETH); //create an instance of Web3 using our account pointing to our nethereum testchain web3 = new Web3(account, web3Url); } Response.AppendHeader("Access-Control-Allow-Origin", "*"); // Get balance of user to deposit. var balance = await web3.Eth.GetBalance.SendRequestAsync(user.CryptoWallet); //// Get eth from Ropsten test network var url = depositToRopsten + user.CryptoWallet; var client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(url); if (!response.IsSuccessStatusCode) { return(Content("False")); } // Get current ETH after deposit from Ropsten. balance = await web3.Eth.GetBalance.SendRequestAsync(user.CryptoWallet); var BalanceAfterDeposit = Web3.Convert.FromWei(balance.Value); var results = new CryptoViewModel { UserName = user.Email, CryptoWalletValue = BalanceAfterDeposit }; return(RedirectToAction("Index", results)); }
public async Task <ActionResult> WithDraw(decimal withDraw) { // Get current user var currentUser = _context.Users.FirstOrDefault(c => c.UserName == User.Identity.Name); var web3 = new Web3(); // Get ETH private ETH adres of Sender if (currentUser.Email == "*****@*****.**") { var account = new Account(staffmemberPrivateETH); //create an instance of Web3 using our account pointing to our nethereum testchain web3 = new Web3(account, web3Url); } else if (currentUser.Email == "*****@*****.**") { var account = new Account(studentPrivateETH); //create an instance of Web3 using our account pointing to our nethereum testchain web3 = new Web3(account, web3Url); } // Check the balance of the account we are going to send the Ether from var balanceFromSender = await web3.Eth.GetBalance.SendRequestAsync(currentUser.CryptoWallet); if (Web3.Convert.FromWei(balanceFromSender.Value) > withDraw) { // transfer var transaction = await web3.Eth.GetEtherTransferService() .TransferEtherAndWaitForReceiptAsync(bankETHAddress, withDraw); var BalanceAfterDeposit = Web3.Convert.FromWei(balanceFromSender.Value); var results = new CryptoViewModel { UserName = currentUser.Email, CryptoWalletValue = BalanceAfterDeposit }; return(RedirectToAction("Index", results)); } else { return(View()); } }
// GET: Cryptos public ActionResult Index(CryptoViewModel cvm = null) { if (cvm == null) { cvm = new CryptoViewModel(); } if (cvm?.PlainText.IsNullOrWhiteSpace() == false) { cvm.EncodedText = cvm.PlainText.ToEncodedBase64UrlSafe(); } else { if (cvm?.EncodedText.IsNullOrWhiteSpace() == false) { cvm.PlainText = cvm.EncodedText.ToPlainText(); } } return(View(cvm)); }
// GET: CryptoPayment public async Task <ActionResult> Index(string Username) { // get current user var user = _context.Users.FirstOrDefault(c => c.UserName == Username); // Web3 koppeling maken var web3 = new Web3(web3Url); // Get users current balance var balance = await web3.Eth.GetBalance.SendRequestAsync(user.CryptoWallet); // Get current ETH value var etherAmount = Web3.Convert.FromWei(balance.Value); var results = new CryptoViewModel { UserName = user.Email, CryptoWalletValue = etherAmount }; return(View(results)); }