Пример #1
0
        private string GenerateToken()
        {
            string password = DateTime.UtcNow.ToString("yyyyMMddHHmmss") + server.ClientKey;
            string token    = AES128.Encrypt(password, server.SecretKey);

            return(token);
        }
Пример #2
0
        /// <summary>
        /// token issue
        /// </summary>
        /// <param name="data">access token data</param>
        /// <typeparam name="T">type of access token</typeparam>
        /// <returns></returns>
        public static string IssueToken <T>(T data) where T : AccessToken
        {
            string dataString = JsonConvert.SerializeObject(data);
            string token      = AES128.Encrypt(dataString, DefaultKey);

            return(token);
        }
Пример #3
0
        private string GetHeaders()
        {
            var password = DateTime.UtcNow.ToString("yyyyMMddHHmmss") + "FiiiPay";
            var token    = AES128.Encrypt(password, "nHf29ryC31hQXrzsSjM7bDYs8v7AT8n54tl3nHBrpB1TM9HhXJ48hOpQrzy9XrQB");

            return(token);
        }
Пример #4
0
        private static string GenerateToken(string clientKey, string secretKey)
        {
            string password = DateTime.UtcNow.ToString("yyyyMMddHHmmss") + clientKey;
            string token    = AES128.Encrypt(password, secretKey);

            return(token);
        }
Пример #5
0
        public void ChangePassword(string oldPassword, string newPassword)
        {
            SettingComponent sComponent = new SettingComponent();
            var setting = sComponent.GetSetting();

            if (MD5Helper.EncryptTo32(oldPassword) == setting.PassCiphertext)
            {
                var aclist = AccountDac.Default.SelectAll();
                foreach (var item in aclist)
                {
                    item.PrivateKey = AES128.Decrypt(item.PrivateKey, oldPassword);
                    item.PrivateKey = AES128.Encrypt(item.PrivateKey, newPassword);
                }
                try
                {
                    AccountDac.Default.UpdatePrivateKeyAr(aclist);
                    setting                = sComponent.GetSetting();
                    setting.Encrypt        = true;
                    setting.PassCiphertext = MD5Helper.EncryptTo32(newPassword);
                    sComponent.SaveSetting(setting);
                }
                catch (Exception ex)
                {
                    throw new CommonException(ErrorCode.Engine.Wallet.DB.EXECUTE_SQL_ERROR, ex);
                }
            }
            else
            {
                throw new CommonException(ErrorCode.Engine.Wallet.CHECK_PASSWORD_ERROR);
            }
        }
Пример #6
0
        public bool EncryptWallet(string salt)
        {
            bool result = false;
            var  aclist = AccountDac.Default.SelectAll();

            foreach (var item in aclist)
            {
                item.PrivateKey = AES128.Encrypt(item.PrivateKey, salt);
            }
            try
            {
                AccountDac.Default.UpdatePrivateKeyAr(aclist);

                SettingComponent sComponent = new SettingComponent();
                var setting = sComponent.GetSetting();
                setting.Encrypt        = true;
                setting.PassCiphertext = MD5Helper.EncryptTo32(salt);
                sComponent.SaveSetting(setting);
                result = true;
            }
            catch (Exception ex)
            {
                throw new CommonException(ErrorCode.Engine.Wallet.DB.EXECUTE_SQL_ERROR, ex);
            }

            return(result);
        }
Пример #7
0
        private string GenerateToken(ProfileRouter router)
        {
            var password = DateTime.UtcNow.ToString("yyyyMMddHHmmss") + router.ClientKey;
            var token    = AES128.Encrypt(password, router.SecretKey);

            return(token);
        }
Пример #8
0
        private string GenerateToken()
        {
            var password = DateTime.UtcNow.ToString("yyyyMMddHHmmss") + ClientKey;
            var token    = AES128.Encrypt(password, SecretKey);

            return(token);
        }
Пример #9
0
        private Dictionary <string, string> GetHeaders()
        {
            var password = DateTime.UtcNow.ToString("yyyyMMddHHmmss") + _router.ClientKey;
            var token    = AES128.Encrypt(password, _router.SecretKey);

            return(new Dictionary <string, string> {
                { "Authorization", "bearer " + token }
            });
        }
Пример #10
0
        private static string GetToken()
        {
            string clientKey = "FiiiPay";
            string secretKey = "u6lvFYbMPlWf9nIHM5KItktyAl2trgUfWSnVB6qW4Uf6IrU8I0LciAK7ZvaLU5fW";
            string password  = DateTime.UtcNow.ToString("yyyyMMddHHmmss") + clientKey;
            string token     = AES128.Encrypt(password, secretKey);

            return(token);
        }
Пример #11
0
        private string GenerateToken()
        {
            string clientKey = ConfigurationManager.AppSettings["ClientKey"];
            string secretKey = ConfigurationManager.AppSettings["SecretKey"];
            string password  = DateTime.UtcNow.ToString("yyyyMMddHHmmss") + clientKey;
            string token     = AES128.Encrypt(password, secretKey);

            return(token);
        }
Пример #12
0
        public IRpcMethodResult GetNewAddress(string tag)
        {
            try
            {
                var       accountComponent = new AccountComponent();
                Account   account          = null;
                var       setting          = new SettingComponent().GetSetting();
                AccountOM result           = null;

                if (setting.Encrypt)
                {
                    if (!string.IsNullOrWhiteSpace(_cache.Get <string>("WalletPassphrase")))
                    {
                        account            = accountComponent.GenerateNewAccount();
                        account.IsDefault  = true;
                        account.PrivateKey = AES128.Encrypt(account.PrivateKey, _cache.Get <string>("WalletPassphrase"));
                        accountComponent.UpdatePrivateKeyAr(account);
                    }
                    else
                    {
                        throw new CommonException(ErrorCode.Service.Wallet.WALLET_HAS_BEEN_LOCKED);
                    }
                }
                else
                {
                    account           = accountComponent.GenerateNewAccount();
                    account.IsDefault = true;
                }

                if (account != null)
                {
                    account.Tag = tag;
                    accountComponent.UpdateTag(account.Id, tag);

                    result           = new AccountOM();
                    result.Address   = account.Id;
                    result.PublicKey = account.PublicKey;
                    result.Balance   = account.Balance;
                    result.IsDefault = account.IsDefault;
                    result.WatchOnly = account.WatchedOnly;
                    result.Tag       = account.Tag;
                }

                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }
Пример #13
0
        private static void SaveFile <T>(T obj, string filePath, string salt)
        {
            string jsonString    = JsonConvert.SerializeObject(obj);
            string encryptString = jsonString;

            if (!string.IsNullOrEmpty(salt))
            {
                encryptString = AES128.Encrypt(jsonString, salt);
            }
            FileHelper.StringSaveFile(encryptString, filePath);
        }
Пример #14
0
        public void TestBytes()
        {
            byte[] key = Enumerable.Range(100, 16).Select(val => (byte)val).ToArray();
            byte[] IV  = Enumerable.Range(128, 16).Select(val => (byte)val).ToArray();

            byte[] testData = Enumerable.Range(0, 256).Select(val => (byte)val).ToArray();

            var encData = AES128.Encrypt(testData, key, IV);

            var decodeData = AES128.Decrypt(encData, key, IV);

            Assert.IsTrue(testData.SequenceEqual(decodeData));
        }
Пример #15
0
        public ServiceResult ModifyEmail(ModifyEmailModel model)
        {
            var result = new ServiceResult();

            if (!ModelState.IsValid)
            {
                result.Code = ReasonCode.MISSING_REQUIRED_FIELDS;
                foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)))
                {
                    result.Message += error + Environment.NewLine;
                }

                return(result);
            }
            var accountId = this.WorkContext.MerchantId;


            new ProfileComponent().ModifyEmail(accountId, model.Code, AES128.Encrypt(model.Token, AES128.DefaultKey));

            return(result);
        }
Пример #16
0
 public static string GetEncryptString(string str)
 {
     return(AES128.Encrypt(str + "_" + DateTime.UtcNow.ToUnixTime(), DefaultKey));
 }
Пример #17
0
        public IRpcMethodResult SendMany(string fromAccount, SendManyOutputIM[] receivers, string[] feeDeductAddresses)
        {
            try
            {
                string result                      = null;
                var    utxoComponent               = new UtxoComponent();
                var    txComponent                 = new TransactionComponent();
                var    settingComponent            = new SettingComponent();
                var    addressBookComponent        = new AddressBookComponent();
                var    accountComponent            = new AccountComponent();
                var    transactionCommentComponent = new TransactionCommentComponent();
                var    blockComponent              = new BlockComponent();
                var    lastBlockHeight             = blockComponent.GetLatestHeight();

                var    setting     = settingComponent.GetSetting();
                var    utxos       = utxoComponent.GetAllConfirmedOutputs();
                var    tx          = new TransactionMsg();
                double totalOutput = 0;
                var    totalSize   = tx.Serialize().Length;

                if (receivers == null || receivers.Length == 0)
                {
                    throw new CommonException(ErrorCode.Service.Transaction.TO_ADDRESS_INVALID);
                }

                foreach (var receiver in receivers)
                {
                    if (!AccountIdHelper.AddressVerify(receiver.address))
                    {
                        throw new CommonException(ErrorCode.Service.Transaction.TO_ADDRESS_INVALID);
                    }

                    var output = new OutputMsg();
                    output.Amount     = receiver.amount;
                    output.Index      = tx.Outputs.Count;
                    output.LockScript = Script.BuildLockScipt(receiver.address);
                    output.Size       = output.LockScript.Length;
                    tx.Outputs.Add(output);

                    totalSize   += output.Serialize().Length;
                    totalOutput += receiver.amount;
                }

                foreach (var address in feeDeductAddresses)
                {
                    if (receivers.Where(r => r.address == address).Count() == 0)
                    {
                        throw new CommonException(ErrorCode.Service.Transaction.FEE_DEDUCT_ADDRESS_INVALID);
                    }
                }

                var    totalInput  = 0L;
                var    index       = 0;
                double totalFee    = setting.FeePerKB * ((double)totalSize / 1024.0);
                double totalAmount = totalOutput;

                while (index < utxos.Count)
                {
                    var account = accountComponent.GetAccountById(utxos[index].AccountId);

                    if (account != null && !string.IsNullOrWhiteSpace(account.PrivateKey))
                    {
                        var   utxoTX    = txComponent.GetTransactionMsgByHash(utxos[index].TransactionHash);
                        Block utxoBlock = blockComponent.GetBlockEntiytByHash(utxos[index].BlockHash);

                        if (utxoTX == null || utxoBlock == null)
                        {
                            index++;
                            continue;
                        }

                        if (!utxoBlock.IsVerified)
                        {
                            index++;
                            continue;
                        }

                        if (Time.EpochTime < utxoTX.Locktime)
                        {
                            index++;
                            continue;
                        }

                        if (utxoTX.InputCount == 1 && utxoTX.Inputs[0].OutputTransactionHash == Base16.Encode(HashHelper.EmptyHash()))
                        {
                            var blockHeight = utxoBlock.Height;

                            if (lastBlockHeight - blockHeight < 100L)
                            {
                                index++;
                                continue;
                            }
                        }

                        var input = new InputMsg();
                        input.OutputTransactionHash = utxos[index].TransactionHash;
                        input.OutputIndex           = utxos[index].OutputIndex;
                        input.UnlockScript          = Script.BuildUnlockScript(input.OutputTransactionHash, input.OutputIndex, Base16.Decode(decryptPrivateKey(account.PrivateKey)), Base16.Decode(account.PublicKey));
                        input.Size = input.UnlockScript.Length;
                        tx.Inputs.Add(input);

                        var size = input.Serialize().Length;
                        totalSize  += size;
                        totalFee   += setting.FeePerKB * ((double)size / 1024.0);
                        totalInput += utxos[index].Amount;
                    }
                    else
                    {
                        index++;
                        continue;
                    }

                    if (feeDeductAddresses == null || feeDeductAddresses.Length == 0)
                    {
                        totalAmount = totalOutput + totalFee;
                    }

                    if (totalInput >= (long)Math.Ceiling(totalAmount))
                    {
                        var size = tx.Outputs[0].Serialize().Length;

                        if ((totalInput - (long)Math.Ceiling(totalAmount)) > (setting.FeePerKB * (double)size / 1024.0))
                        {
                            totalSize += size;
                            totalFee  += setting.FeePerKB * ((double)size / 1024.0);

                            if (feeDeductAddresses == null || feeDeductAddresses.Length == 0)
                            {
                                totalAmount = totalOutput + totalFee;
                            }


                            var newAccount = accountComponent.GenerateNewAccount();

                            if (setting.Encrypt)
                            {
                                if (!string.IsNullOrWhiteSpace(_cache.Get <string>("WalletPassphrase")))
                                {
                                    newAccount.PrivateKey = AES128.Encrypt(newAccount.PrivateKey, _cache.Get <string>("WalletPassphrase"));
                                    accountComponent.UpdatePrivateKeyAr(newAccount);
                                }
                                else
                                {
                                    throw new CommonException(ErrorCode.Service.Wallet.WALLET_HAS_BEEN_LOCKED);
                                }
                            }

                            var newOutput = new OutputMsg();
                            newOutput.Amount     = totalInput - (long)Math.Ceiling(totalAmount);
                            newOutput.Index      = tx.Outputs.Count;
                            newOutput.LockScript = Script.BuildLockScipt(newAccount.Id);
                            newOutput.Size       = newOutput.LockScript.Length;
                            tx.Outputs.Add(newOutput);
                        }

                        break;
                    }

                    index++;
                }

                if (totalInput < totalAmount)
                {
                    throw new CommonException(ErrorCode.Service.Transaction.BALANCE_NOT_ENOUGH);
                }

                if (feeDeductAddresses != null && feeDeductAddresses.Length > 0)
                {
                    var averageFee = totalFee / feeDeductAddresses.Length;

                    for (int i = 0; i < receivers.Length; i++)
                    {
                        if (feeDeductAddresses.Contains(receivers[i].address))
                        {
                            tx.Outputs[i].Amount -= (long)Math.Ceiling(averageFee);

                            if (tx.Outputs[i].Amount <= 0)
                            {
                                throw new CommonException(ErrorCode.Service.Transaction.SEND_AMOUNT_LESS_THAN_FEE);
                            }
                        }
                    }
                }

                tx.Timestamp = Time.EpochTime;
                tx.Hash      = tx.GetHash();
                txComponent.AddTransactionToPool(tx);
                Startup.P2PBroadcastTransactionAction(tx.Hash);
                result = tx.Hash;

                for (int i = 0; i < receivers.Length; i++)
                {
                    var receiver = receivers[i];

                    if (!string.IsNullOrWhiteSpace(receiver.tag))
                    {
                        addressBookComponent.SetTag(receiver.address, receiver.tag);
                    }

                    if (!string.IsNullOrWhiteSpace(receiver.comment))
                    {
                        transactionCommentComponent.Add(tx.Hash, i, receiver.comment);
                    }
                }

                return(Ok(result));
            }
            catch (CommonException ce)
            {
                return(Error(ce.ErrorCode, ce.Message, ce));
            }
            catch (Exception ex)
            {
                return(Error(ErrorCode.UNKNOWN_ERROR, ex.Message, ex));
            }
        }