Пример #1
0
        public string base64Decode(object obj)
        {
            try
            {
                string data = obj != null?obj.ToString() : string.Empty;

                if (string.IsNullOrEmpty(data))
                {
                    return(string.Empty);
                }
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();

                byte[] todecode_byte = Convert.FromBase64String(data);
                int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                char[] decoded_char  = new char[charCount];
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                string result = new String(decoded_char);
                return(result);
            }
            catch (Exception e)
            {
                throw new Exception("Error in base64Decode" + e.Message);
            }
        }
Пример #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="clave"></param>
        /// <returns></returns>
        public static string DecryptKeyBase64(string clave)
        {
            string Password = clave.Substring(clave.IndexOf("Password="******";"));

            try
            {
                string result;
                if (Password != null)
                {
                    var encoder    = new System.Text.UTF8Encoding();
                    var utf8Decode = encoder.GetDecoder();

                    byte[] cadenaByte  = Convert.FromBase64String(Password);
                    int    charCount   = utf8Decode.GetCharCount(cadenaByte, 0, cadenaByte.Length);
                    char[] decodedChar = new char[charCount];
                    utf8Decode.GetChars(cadenaByte, 0, cadenaByte.Length, decodedChar, 0);
                    result = new String(decodedChar);
                }
                else
                {
                    result = "";
                }

                clave = clave.Replace(Password, result);
                return(clave);
            }
            catch (Exception ex)
            {
                log.Error(ex.Message);
            }
            return("");
        }
        public IHttpActionResult CheckTransactionPassword(long account_number, string transaction_password)
        {
            try
            {
                string password = db.AccountHolders.Where(a => a.account_number == account_number).Select(a => a.transaction_password).ToList()[0];

                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();
                byte[] todecode_byte = Convert.FromBase64String(password);
                int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                char[] decoded_char  = new char[charCount];
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                string decrypt_transaction_password = new String(decoded_char);


                if (decrypt_transaction_password == transaction_password)
                {
                    return(Ok("Passwords Match"));
                }
                else
                {
                    return(Ok("Error"));
                }
            }
            catch (Exception e)
            {
                return(Ok("Error"));
            }
        }
Пример #4
0
 /// <summary>
 /// Base64解密
 /// </summary>
 /// <param name="Message">需要解密的字符串</param>
 /// <returns></returns>
 public string Base64Decode(string Message)
 {
     try
     {
         string result = "";
         if (isEncrypt)
         {
             Message = Message.Replace(" ", "+");
             string gbStr = System.Text.Encoding.GetEncoding("utf-8").GetString(System.Text.Encoding.Default.GetBytes(Message));
             System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
             System.Text.Decoder utf8Decode = encoder.GetDecoder();
             byte[] todecode_byte = Convert.FromBase64String(Message);
             int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
             char[] decoded_char = new char[charCount];
             utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
             result = new String(decoded_char);
         }
         else
         {
             result = Message;
         }
         return result;
     }
     catch (Exception e)
     {
         throw new Exception("Error in base64Decode" + e.Message);
     }
 }
Пример #5
0
        public void ExportPurchaseInvoice(string encrift)
        {
            List <Purchase> purchase = new List <Purchase>();

            byte[] b = Convert.FromBase64String(encrift);
            System.Text.UTF8Encoding encoder     = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decoder = encoder.GetDecoder();

            int charCount = utf8Decoder.GetCharCount(b, 0, b.Length);

            char[] decodedChar = new char[charCount];
            utf8Decoder.GetChars(b, 0, b.Length, decodedChar, 0);
            string result = new string(decodedChar);

            JavaScriptSerializer js = new JavaScriptSerializer();

            Purchase[] PurchaseList = js.Deserialize <Purchase[]>(result);

            foreach (var a in PurchaseList)
            {
                Purchase aPurchase = new Purchase();
                aPurchase.PurchaseNo   = a.PurchaseNo;
                aPurchase.PurchaseDate = a.PurchaseDate;
                aPurchase.PurchaseSupplierInvoiceNo = a.PurchaseSupplierInvoiceNo;
                aPurchase.ProductCode          = db.productDetails.First(p => p.ProductDetailsID == a.PurchaseProductID).Code;
                aPurchase.ProductName          = db.productDetails.First(p => p.ProductDetailsID == a.PurchaseProductID).ProductName;
                aPurchase.PurchaseProductPrice = a.PurchaseProductPrice;
                aPurchase.PurchaseQuantity     = a.PurchaseQuantity;
                aPurchase.PurchaseTotal        = a.PurchaseTotal;
                aPurchase.TotalAmount          = a.TotalAmount;
                purchase.Add(aPurchase);
            }
            ReportDataSource reportDataSource = new ReportDataSource();

            reportDataSource.Name  = "PurchaseDataSet";
            reportDataSource.Value = purchase;

            string mimeType          = string.Empty;
            string encodeing         = string.Empty;
            string fileNameExtension = "pdf";

            Warning[] warnings;
            string[]  streams;

            LocalReport localReport = new LocalReport();

            localReport.ReportPath = Server.MapPath("~/Report/Purchase/PurchaseReport.rdlc");
            localReport.DataSources.Add(reportDataSource);

            byte[] bytes = localReport.Render("PDF", null, out mimeType, out encodeing, out fileNameExtension, out streams, out warnings);

            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", "attachment;filename=file." + fileNameExtension);
            Response.BinaryWrite(bytes);
            Response.Flush();
        }
Пример #6
0
 //this function Convert to Decord your Password
 public static string DecodeFrom64(string encodedData)
 {
     System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
     System.Text.Decoder utf8Decode = encoder.GetDecoder();
     byte[] todecode_byte = Convert.FromBase64String(encodedData);
     int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
     char[] decoded_char = new char[charCount];
     utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
     string result = new String(decoded_char);
     return result;
 }
Пример #7
0
        public static string Decrypt(this string str)
        {
            System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decode = encoder.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(str);
            int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);

            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            return(new string(decoded_char));
        }
        private string Base64Decode(string encodedData)
        {
            var encoder    = new System.Text.UTF8Encoding();
            var utf8Decode = encoder.GetDecoder();

            byte[] todecodeByte = Convert.FromBase64String(encodedData);
            int    charCount    = utf8Decode.GetCharCount(todecodeByte, 0, todecodeByte.Length);

            char[] decodedChar = new char[charCount];
            utf8Decode.GetChars(todecodeByte, 0, todecodeByte.Length, decodedChar, 0);
            return(new String(decodedChar));
        }
Пример #9
0
        public static T DecodeFromBase64String <T>(string base64String)
        {
            System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decode = encoder.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(base64String);
            int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);

            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string decoded_string = new String(decoded_char);

            return(JsonConvert.DeserializeObject <T>(decoded_string));
        }
        private string DecodePassword(string encodedData)
        {
            System.Text.UTF8Encoding encoder     = new System.Text.UTF8Encoding();
            System.Text.Decoder      decodedCode = encoder.GetDecoder();
            byte[] decodedBydeCode = Convert.FromBase64String(encodedData);
            int    charCount       = decodedCode.GetCharCount(decodedBydeCode, 0, decodedBydeCode.Length);

            char[] decodedChar = new char[charCount];
            decodedCode.GetChars(decodedBydeCode, 0, decodedBydeCode.Length, decodedChar, 0);
            string result = new String(decodedChar);

            return(result);
        }
Пример #11
0
        public string DecryptPassword(string encryptedCode)
        {
            System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decode = encoder.GetDecoder();
            byte[] decryptByte = Convert.FromBase64String(encryptedCode);
            int    charCount   = utf8Decode.GetCharCount(decryptByte, 0, decryptByte.Length);

            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(decryptByte, 0, decryptByte.Length, decoded_char, 0);
            string password = new String(decoded_char);

            return(password);
        }
Пример #12
0
        public static string DecodeFrom64(string encodedData)
        {
            System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decode = encoder.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(encodedData);
            int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);

            char[] decoded_char = new char[charCount];
            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string result = new String(decoded_char);

            return(result);
        }
Пример #13
0
        public static string base64Decode(string sData)
        {
            var encoder       = new System.Text.UTF8Encoding();
            var utf8Decode    = encoder.GetDecoder();
            var todecode_byte = Convert.FromBase64String(sData);
            int charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
            var decoded_char  = new char[charCount];

            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            string result = new string(decoded_char);

            return(result);
        }
Пример #14
0
        public string DecodePasswordFromBase64(string encodedData, string ResetCode)
        {
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder      decoder = encoder.GetDecoder();
            byte[] decodePassword            = Convert.FromBase64String(encodedData);
            int    charCount = decoder.GetCharCount(decodePassword, 0, decodePassword.Length);

            char[] decodedChar = new char[charCount];
            decoder.GetChars(decodePassword, 0, decodePassword.Length, decodedChar, 0);
            string decodedData = new string(decodedChar);

            return(decodedData);
        }
Пример #15
0
        private string Decrypt_Password(string encryptpassword)
        {
            string pswstr = string.Empty;

            System.Text.UTF8Encoding encode_psw = new System.Text.UTF8Encoding();
            System.Text.Decoder      Decode     = encode_psw.GetDecoder();
            byte[] todecode_byte = Convert.FromBase64String(encryptpassword);
            int    charCount     = Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);

            char[] decoded_char = new char[charCount];
            Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
            pswstr = new String(decoded_char);
            return(pswstr);
        }
        //Student student
        //List<Student> student
        public void ExportTo(string id)
        {
            List <Student> a = new List <Student>();

            byte[] b = Convert.FromBase64String(id);
            System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decode = encoder.GetDecoder();

            int charCount = utf8Decode.GetCharCount(b, 0, b.Length);

            char[] decodedChar = new char[charCount];
            utf8Decode.GetChars(b, 0, b.Length, decodedChar, 0);
            string result = new String(decodedChar);

            JavaScriptSerializer js = new JavaScriptSerializer();

            Student[] student = js.Deserialize <Student[]>(result);


            ReportDataSource reportDataSource = new ReportDataSource();

            reportDataSource.Name  = "DataSet";
            reportDataSource.Value = student;

            string mimeType          = string.Empty;
            string encodeing         = string.Empty;
            string fileNameExtension = "pdf";

            Warning[] warnings;
            string[]  streams;

            LocalReport localReport = new LocalReport();

            localReport.ReportPath = Server.MapPath("~/Report/Report.rdlc");
            localReport.DataSources.Add(reportDataSource);

            byte[] bytes = localReport.Render("PDF", null, out mimeType, out encodeing, out fileNameExtension, out streams, out warnings);

            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", "attachment;filename=file." + fileNameExtension);
            //Response.Flush();
            Response.BinaryWrite(bytes);
            Response.Flush();

            //Response.Close();
            //return File(bytes, fileNameExtension);
        }
        public void ExportSaleInvoice(string encrift)
        {
            byte[] b = Convert.FromBase64String(encrift);
            System.Text.UTF8Encoding encoder     = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decoder = encoder.GetDecoder();

            int charCount = utf8Decoder.GetCharCount(b, 0, b.Length);

            char[] decodedChar = new char[charCount];
            utf8Decoder.GetChars(b, 0, b.Length, decodedChar, 0);
            string result = new string(decodedChar);

            JavaScriptSerializer js = new JavaScriptSerializer();

            Sale[] SaleList = js.Deserialize <Sale[]>(result);

            ReportDataSource reportDataSource = new ReportDataSource();

            reportDataSource.Name  = "SalesDataSet";
            reportDataSource.Value = SaleList;

            string mimeType          = string.Empty;
            string encodeing         = string.Empty;
            string fileNameExtension = "pdf";

            Warning[] warnings;
            string[]  streams;

            LocalReport localReport = new LocalReport();

            localReport.ReportPath = Server.MapPath("~/Report/Sale/SaleReport.rdlc");
            localReport.DataSources.Add(reportDataSource);

            byte[] bytes = localReport.Render("PDF", null, out mimeType, out encodeing, out fileNameExtension, out streams, out warnings);

            Response.Buffer = true;
            Response.Clear();
            Response.ContentType = mimeType;
            Response.AddHeader("content-disposition", "attachment;filename=file." + fileNameExtension);
            Response.BinaryWrite(bytes);
            Response.Flush();

            //var pq = LocalPrintServer.GetDefaultPrintQueue();
            //using (var job = pq.AddJob())
            //using (var s = job.JobStream)
            //{
            //    s.Write(bytes, 0, bytes.Length);
            //}
        }
        public IActionResult Sub40()
        {
            Boolean checkLogin = CheckLogin();

            if (!checkLogin)
            {
                return(RedirectToAction("Login", "Account"));
            }

            ViewBag.menulist = menulist;
            //_logger.LogInformation("sub40(): " + LoginUser.BizNum + " / " + LoginUser.StaffId);

            List <문서함> mySign = null;

            _db.LoadStoredProc("dbo.file_getSignature").AddParam("BizNum", LoginUser.BizNum).AddParam("StaffId", LoginUser.StaffId)
            .AddParam("Dname", LoginUser.Dname).Exec(r => mySign = r.ToList <문서함>());

            if (mySign.Count > 0)
            {
                // 2020년 7월 15일 부터 개인서명 저장방식 변경되어 convert
                if (mySign[0].Regdate > Convert.ToDateTime("2020-07-15"))
                {
                    var stringify_byte = Convert.ToBase64String(mySign[0].FileBlob);
                    //Console.WriteLine("tobase64 : " + stringify_byte);
                    string result = "data:image/png;base64," + stringify_byte;
                    ViewBag.mySign = result;
                }
                else
                {   // 기존 서명 저장방식에서 불러오기
                    var stringify_byte = Convert.ToBase64String(mySign[0].FileBlob);
                    System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                    System.Text.Decoder      utf8Decode = encoder.GetDecoder();
                    byte[] todecode_byte = Convert.FromBase64String(stringify_byte);
                    //Console.WriteLine("byte: " + todecode_byte);
                    int    charCount    = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                    char[] decoded_char = new char[charCount];
                    utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                    string result = new String(decoded_char);
                    //Console.WriteLine("result: " + result);
                    ViewBag.mySign = result;
                }
                ViewBag.SEQID = mySign[0].SeqId;

                return(View());
            }

            return(View());
        }
Пример #19
0
        public static string base64Decode(string data)
        {
            try {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();

                byte[] todecode_byte = Convert.FromBase64String(data);
                int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                char[] decoded_char  = new char[charCount];
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                string result = new String(decoded_char);
                return(result);
            } catch (Exception e) {
                throw new Exception("Error in base64Decode" + e.Message);
            }
        }
Пример #20
0
        /// <summary>
        /// Decode a Base64 encoded string.
        /// </summary>
        public string Base64Decode(string data)
        {
            if (!string.IsNullOrEmpty(data))
            {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();

                byte[] bytToDecode = Convert.FromBase64String(data);
                int    charCount   = utf8Decode.GetCharCount(bytToDecode, 0, bytToDecode.Length);
                char[] chrDecoded  = new char[charCount];
                utf8Decode.GetChars(bytToDecode, 0, bytToDecode.Length, chrDecoded, 0);
                return(new String(chrDecoded));
            }

            return(null);
        }
Пример #21
0
 public string decodePassword(string encodedData)
 {
     try
     {
         System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
         System.Text.Decoder      utf8Decode = encoder.GetDecoder();
         byte[] todecode_byte = Convert.FromBase64String(encodedData);
         int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
         char[] decoded_char  = new char[charCount];
         utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
         return(new String(decoded_char));
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
 }
Пример #22
0
        public static string Decode(byte[] data)
        {
            try
            {
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
                System.Text.Decoder utf8Decode = encoder.GetDecoder();

                int charCount = utf8Decode.GetCharCount(data, 0, data.Length);
                char[] decoded_char = new char[charCount];
                utf8Decode.GetChars(data, 0, data.Length, decoded_char, 0);
                string result = new String(decoded_char);
                return result;
            }
            catch (Exception e)
            {
                throw new Exception("Error decoding base64 data: " + e.Message);
            }
        }
Пример #23
0
        /// <summary>
        /// Desencripta un texto encriptado en base64
        /// </summary>
        /// <param fileName="cadena">string</param>
        /// <returns></returns>
        public static string Base64Decrypt(string cadena_encriptada)
        {
            if (null == cadena_encriptada)
            {
                throw new ArgumentNullException("No se ha indicado la cadena para desencriptar (Factory.Core.Crypy: DecryptBase64)");
            }
            var encoder    = new System.Text.UTF8Encoding( );
            var utf8Decode = encoder.GetDecoder( );

            byte[] cadenaByte = Convert.FromBase64String(cadena_encriptada);
            int    charCount  = utf8Decode.GetCharCount(cadenaByte, 0, cadenaByte.Length);

            char[] decodedChar = new char[charCount];
            utf8Decode.GetChars(cadenaByte, 0, cadenaByte.Length, decodedChar, 0);
            string result = new System.String(decodedChar);

            return(result);
        }
 /// <summary>
 /// Decodes the password.
 /// </summary>
 /// <param name="password">password.</param>
 /// <returns>Returns the Decoded password.</returns>
 private string DecodePassword(string password)
 {
     try
     {
         System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
         System.Text.Decoder      utf8Decode = encoder.GetDecoder();
         byte[] todecode_byte = Convert.FromBase64String(password);
         int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
         char[] decoded_char  = new char[charCount];
         utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
         string result = new String(decoded_char);
         return(result);
     }
     catch (TweetException ex)
     {
         throw new TweetException("error in decode password" + ex.Message);
     }
 }
Пример #25
0
 /// Base64解密
 public static string Base64Decode(string Message)
 {
     try
     {
         System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
         System.Text.Decoder utf8Decode = encoder.GetDecoder();
         byte[] todecode_byte = Convert.FromBase64String(Message);
         int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
         char[] decoded_char = new char[charCount];
         utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
         string result = new String(decoded_char);
         return result;
     }
     catch (Exception e)
     {
         throw new Exception("Error in base64Decode" + e.Message);
     }
 }
Пример #26
0
 public static string base64Decode(string sData)
 {
     try
     {
         System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
         System.Text.Decoder      utf8Decode = encoder.GetDecoder();
         byte[] todecode_byte = Convert.FromBase64String(sData);
         int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
         char[] decoded_char  = new char[charCount - 1 + 1];
         utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char.ToString().ToCharArray(), 0);
         string result = new String(decoded_char);
         return(result);
     }
     catch (Exception ex)
     {
         throw (new Exception(System.Reflection.MethodInfo.GetCurrentMethod().ToString() + " . Error when decoding: " + ex.Message));
     }
 }
Пример #27
0
        /// <summary>
        /// Decode a Base64 encoded string.
        /// </summary>
        public string Base64Decode(string data)
        {
            try
            {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();

                byte[] bytToDecode = Convert.FromBase64String(data);
                int    charCount   = utf8Decode.GetCharCount(bytToDecode, 0, bytToDecode.Length);
                char[] chrDecoded  = new char[charCount];
                utf8Decode.GetChars(bytToDecode, 0, bytToDecode.Length, chrDecoded, 0);
                string strResult = new String(chrDecoded);
                return(strResult);
            }
            catch (Exception e)
            {
                throw new Exception("Error in Base64Decode" + e.Message);
            }
        }
Пример #28
0
        public async Task <string> GetMail(dynamic mailid)
        {
            string email = mailid.mailid;

            if (mailid != null)
            {
                // TO check whether email is present or not if yes, then password will be sent to the registered Emailid.
                if (Db.UserRegisters.FirstOrDefault(u => u.UserEmailId == email) is null)
                {
                    return("Invalid Email Id");
                }
                //Random generator = new Random();
                //int r = generator.Next(100000, 1000000);
                string r = (from u in Db.UserRegisters
                            where u.UserEmailId == email
                            select u.password).FirstOrDefault();
                var e = r;

                //Decryption
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();
                byte[] todecode_byte = Convert.FromBase64String(e);
                int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                char[] decoded_char  = new char[charCount];
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                string pass = new String(decoded_char);


                SmtpClient  smtp        = new SmtpClient();
                MailMessage mailMessage = new MailMessage();
                mailMessage.From = new MailAddress("*****@*****.**");
                mailMessage.To.Add(email);
                mailMessage.Subject = "Forgot Password Of Farmer Scheme Web Application.";
                mailMessage.Body    = "Dear User.Your password is " + pass + ". Kindly Remember it for future login into the system";
                await Task.Run(() => smtp.SendAsync(mailMessage, null));

                return(r);
            }
            else
            {
                return("Invalid Email Id");
            }
        }
Пример #29
0
        public static string base64Decode(string sData) //Decode
        {
            if (sData == null)
            {
                return(string.Empty);
            }

            var encoder = new System.Text.UTF8Encoding();

            System.Text.Decoder utf8Decode = encoder.GetDecoder();
            byte[] todecodeByte            = Convert.FromBase64String(sData);
            int    charCount = utf8Decode.GetCharCount(todecodeByte, 0, todecodeByte.Length);

            char[] decodedChar = new char[charCount];
            utf8Decode.GetChars(todecodeByte, 0, todecodeByte.Length, decodedChar, 0);
            string result = new String(decodedChar);

            return(result);
        }
Пример #30
0
        public static string Decode(string data)
        {
            try
            {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();

                byte[] toDecodeByte = Convert.FromBase64String(data);
                int    charCount    = utf8Decode.GetCharCount(toDecodeByte, 0, toDecodeByte.Length);
                char[] decodedChar  = new char[charCount];
                utf8Decode.GetChars(toDecodeByte, 0, toDecodeByte.Length, decodedChar, 0);
                string result = new string(decodedChar);
                return(result);
            }
            catch (Exception)
            {
                throw;
            }
        }
Пример #31
0
        /// <summary>
        /// Decode a Base64 encoded string.
        /// </summary>
        public string Base64Decode(string data)
        {
            try
            {
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
                System.Text.Decoder utf8Decode = encoder.GetDecoder();

                byte[] bytToDecode = Convert.FromBase64String(data);
                int charCount = utf8Decode.GetCharCount(bytToDecode, 0, bytToDecode.Length);
                char[] chrDecoded = new char[charCount];
                utf8Decode.GetChars(bytToDecode, 0, bytToDecode.Length, chrDecoded, 0);
                string strResult = new String(chrDecoded);
                return strResult;
            }
            catch (Exception e)
            {
                throw new Exception("Error in Base64Decode" + e.Message);
            }
        }
 public string Decrypt(string sData)
 {
     try
     {
         System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
         System.Text.Decoder      utf8Decode = encoder.GetDecoder();
         byte[] todecode_byte = Convert.FromBase64String(sData);
         int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
         char[] decoded_char  = new char[charCount];
         utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
         string result = new String(decoded_char);
         return(result);
     }
     catch (Exception ex)
     {
         string message = "error in decrypt: " + ex.Message + " Value: " + sData;
         return(message);
     }
 }
        public static string DecodeFromBase64(string encodedData)
        {
            string result = null;

            try
            {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();
                byte[] todecode_byte = Convert.FromBase64String(encodedData);
                int    charCount     = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                char[] decoded_char  = new char[charCount];
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                result = new String(decoded_char);
            }
            catch (Exception ex)
            {
                result = "Encoded Input is not Valid, Please Check the Input Value - " + encodedData;
            }
            return(result);
        }
Пример #34
0
        public string DecodeBase64BitString(string encodedString)
        {
            try
            {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();

                byte[] todecodeByte = Convert.FromBase64String(encodedString);
                int    charCount    = utf8Decode.GetCharCount(todecodeByte, 0, todecodeByte.Length);
                char[] decodedChar  = new char[charCount];
                utf8Decode.GetChars(todecodeByte, 0, todecodeByte.Length, decodedChar, 0);
                result = new String(decodedChar);
                return(result);
            }
            catch (Exception e)
            {
                result = "Error in Encoded String " + e.Message;
                return(result);
            }
        }
Пример #35
0
        public string llBase64ToString(IScriptInstance script, string str)
        {
            System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
            System.Text.Decoder utf8Decode = encoder.GetDecoder();
            string result = String.Empty;

            try
            {
                byte[] todecode_byte = Convert.FromBase64String(str);
                int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                char[] decoded_char = new char[charCount];
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                result = new String(decoded_char);
            }
            catch (Exception e)
            {
                throw new Exception("Error in base64Decode" + e.Message);
            }

            return result;
        }
Пример #36
0
        /// <summary>
        /// Creates the XmlElement for the third level, or TestGroup level of the 
        /// tree.
        /// </summary>
        /// <param name="doc">
        /// The XmlDocument object that will eventually contain this Element.
        /// </param>
        /// <param name="node">
        /// The TreeNode representation of this TestGroup
        /// </param>
        /// <returns>
        /// The XmlElement that contains the TestGroup and all its children.
        /// </returns>
        private System.Xml.XmlElement SaveTestGroupNodeToXmlElement(
            System.Xml.XmlDocument doc,
            TreeNode node)
        {
            System.Xml.XmlElement ret = doc.CreateElement("TestGroup");
            IUPnPTestGroup group = node.Tag as IUPnPTestGroup;
            if (group != null)
            {
                ret.SetAttribute("name", group.GroupName);
                ret.SetAttribute("state", Util.UPnPTestStatesToString(group.GroupState));
                ret.SetAttribute("description", group.Description);

                for (int i = 0; i < group.TestNames.GetLength(0); i++)
                {
                    string result = "";
                    if (group.Result.GetLength(0) > i)
                    {
                        result = group.Result[i];
                    }
                    System.Xml.XmlElement testElement =
                        SaveTestToXmlElement(
                        doc,
                        group.TestNames[i],
                        Util.UPnPTestStatesToString(group.TestStates[i]),
                        group.TestDescription[i],
                        result,
                        group.Log);

                    ret.AppendChild(testElement);
                }

                // output the packets.  I wish that there were a way to
                // associate this with the individual tests, but it doesn't
                // appear to be possible with the current data structures.
                foreach (HTTPMessage httpMesg in group.PacketTrace)
                {
                    byte[] packetBytes = httpMesg.RawPacket;
                    System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding();
                    System.Text.Decoder utf8Dec = utf8.GetDecoder();
                    int len = packetBytes.Length;
                    char[] packetChars = new char[len];
                    utf8Dec.GetChars(packetBytes, 0, len, packetChars, 0);
                    string packetString = new String(packetChars);

                    System.Xml.XmlElement packetElement =
                        doc.CreateElement("Packet");
                    packetElement.InnerText = packetString;
                    ret.AppendChild(packetElement);
                }
            }
            return ret;
        }
Пример #37
0
        /// <summary>
        /// Decodes a base64 string into a readable string
        /// </summary>
        /// <param name="data">Data to decode</param>
        /// <returns></returns>
        private string base64Decode(string data)
        {
            //add padding with '=' to string to accommodate C# Base64 requirements
            int strlen = data.Length + (4 - (data.Length % 4));
            char pad = '=';
            string datapad;

            if (strlen == (data.Length + 4))
            {
                datapad = data;
            }
            else
            {
                datapad = data.PadRight(strlen, pad);
            }

            try
            {
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
                System.Text.Decoder utf8Decode = encoder.GetDecoder();

                // create byte array to store Base64 string
                byte[] todecode_byte = Convert.FromBase64String(datapad);
                int charCount = utf8Decode.GetCharCount(todecode_byte, 0, todecode_byte.Length);
                char[] decoded_char = new char[charCount];
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                string result = new String(decoded_char);
                return result;
            }
            catch (Exception e)
            {
                throw new Exception("Error in base64Decode: " + e.Message);
            }
        }
	    private string Base64Decode(string encodedData) {
			var encoder = new System.Text.UTF8Encoding();
			var utf8Decode = encoder.GetDecoder();
			byte[] todecodeByte = Convert.FromBase64String(encodedData);
			int charCount = utf8Decode.GetCharCount(todecodeByte, 0, todecodeByte.Length);
			char[] decodedChar = new char[charCount];
			utf8Decode.GetChars(todecodeByte, 0, todecodeByte.Length, decodedChar, 0);
			return new String(decodedChar);
		}
Пример #39
0
 public static string Base64Decode(string sData)
 {
     var encoder = new System.Text.UTF8Encoding();
     System.Text.Decoder utf8Decode = encoder.GetDecoder();
     byte[] todecodeByte = Convert.FromBase64String(sData);
     int charCount = utf8Decode.GetCharCount(todecodeByte, 0, todecodeByte.Length);
     var decodedChar = new char[charCount];
     utf8Decode.GetChars(todecodeByte, 0, todecodeByte.Length, decodedChar, 0);
     var result = new String(decodedChar); return result;
 }