Exemplo n.º 1
0
            /// <summary>Calculates the number of characters produced by decoding a sequence of bytes from the specified byte array</summary>
            /// <param name="bytes">The byte array containing the sequence of bytes to decode.</param>
            /// <param name="index">The index of the first byte to decode.</param>
            /// <param name="count">The number of bytes to decode.</param>
            /// <returns>The number of characters produced by decoding the specified sequence of bytes and any bytes in the internal buffer.</returns>
            /// <remarks>This method does not affect the state of the decoder.</remarks>
            /// <seealso cref="System.Text.Decoder.GetCharCount(Byte[], Int32, Int32)"/>
            public override int GetCharCount(byte[] bytes, int index, int count)
            {
                count = mEncoding.CalculateCharByteCount(bytes, ref index, count);                 // Remove our String Storage calculations

                int char_count = mDec.GetCharCount(bytes, index, count);

                return(char_count);
            }
        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"));
            }
        }
Exemplo n.º 3
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);
            }
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        public static string BytesToString(byte[] bytes)
        {
            System.Text.Decoder decode = System.Text.Encoding.UTF8.GetDecoder();
            long length = decode.GetCharCount(bytes, 0, bytes.Length);

            char[] chars = new char[length];
            decode.GetChars(bytes, 0, bytes.Length, chars, 0);
            string result = new String(chars);

            return(result);
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
        protected string GetDataAsString(byte[] data)
        {
            System.Text.Decoder utf8Decoder = System.Text.Encoding.UTF8.GetDecoder();
            int charCount = utf8Decoder.GetCharCount(data, 0, (data.Length));

            char[] recievedChars = new char[charCount];
            utf8Decoder.GetChars(data, 0, data.Length, recievedChars, 0);
            string recievedString = new String(recievedChars);

            return(recievedString);
        }
Exemplo n.º 8
0
        /// <summary>
        /// We've received data, parse it
        /// </summary>
        private void DataReceived(object sender, ReceiveEventArgs e)
        {
            if ((byte)e.Message.ReceiveData.Read(typeof(byte)) == ChatMessageId)             // We've received text chat
            {
                // We won't be using the helper functions here since we want to
                // interop with the c++ version of the app.  It packages its messages
                // up with the first byte being the msg id (ChatMessageId), and
                // the next xxx bytes as an ANSI string.

                // Get the default ASCII decoder
                System.Text.Decoder dec = System.Text.Encoding.ASCII.GetDecoder();
                int length = (int)e.Message.ReceiveData.Length - 1;
                // Create a char array of the right length
                byte[] data = (byte[])e.Message.ReceiveData.Read(typeof(byte), length);
                char[] c    = new char[dec.GetCharCount(data, 0, length)];
                // Get the actual decoded characters
                dec.GetChars(data, 0, length, c, 0);
                // Now we can use the string builder to actually build our string
                System.Text.StringBuilder sb = new System.Text.StringBuilder(c.Length);
                sb.Insert(0, c, 0, dec.GetCharCount(data, 0, length));

                string sChatText = sb.ToString();                 // The actual chat text
                // Now build the string we will be displaying to the user:
                string sChatString = "<" + GetPlayerName(e.Message.SenderID) + "> " + sChatText;
                // Now update our text
                lock (txtChat)
                {
                    if (txtChat.Text.Length > (txtChat.MaxLength * 0.95))
                    {
                        txtChat.Text = txtChat.Text.Remove(0, (int)(txtChat.MaxLength / 2));
                    }

                    txtChat.AppendText(sChatString);
                    txtChat.AppendText("\r\n");
                    txtChat.SelectionStart = txtChat.Text.Length;
                    txtChat.ScrollToCaret();
                }
            }
            e.Message.ReceiveData.Dispose();             // We no longer need the data, Dispose the buffer
        }
Exemplo n.º 9
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);
        }
Exemplo n.º 10
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);
        }
        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);
        }
Exemplo n.º 12
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));
        }
Exemplo n.º 13
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);
        }
Exemplo n.º 14
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);
        }
        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);
            //}
        }
        //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);
        }
Exemplo n.º 17
0
        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());
        }
Exemplo n.º 18
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);
            }
        }
        /// <summary>
        /// Converts the data passed as an array of bytes to string.
        /// Assumes the data is UTF8 encoded
        /// </summary>
        /// <param name="data">Array of bytes received</param>
        /// <param name="ignoreLastBytes">Number of bytes AT THE END of data, to be ignored.
        /// This parameter is needed because at the end of data could be non-readable info (as CRC)</param>
        protected override String GetDataAsString(byte[] data, int ignoreLastBytes)
        {
            if (data.Length < ignoreLastBytes)
            {
                return("");
            }

            System.Text.Decoder utf8Decoder = System.Text.Encoding.UTF8.GetDecoder();
            int charCount = utf8Decoder.GetCharCount(data, 0, (data.Length - ignoreLastBytes));

            char[] recievedChars = new char[charCount];
            utf8Decoder.GetChars(data, 0, data.Length - ignoreLastBytes, recievedChars, 0);
            String recievedString = new String(recievedChars);

            return(recievedString);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
     }
 }
Exemplo n.º 22
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));
     }
 }
Exemplo n.º 23
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);
            }
        }
 /// <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);
     }
 }
Exemplo n.º 25
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);
        }
Exemplo n.º 26
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;
            }
        }
Exemplo n.º 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);
            }
        }
 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);
     }
 }
Exemplo n.º 29
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");
            }
        }
Exemplo n.º 30
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);
            }
        }