GetDecoder() public method

public GetDecoder ( ) : System.Text.Decoder
return System.Text.Decoder
Esempio n. 1
0
        public string Decryptdata(string imagepath)
        {
            string image = "";
            if (imagepath != "")
            {
                string[] path = { "" };
                path = imagepath.Split('/');
                string baseurl = path[0];
                string filename = path[1];
                string[] withextention = { "" };
                withextention = filename.Split('.');
                string encryptpwd = withextention[0];
                string extention = withextention[1];
                string decryptpwd = string.Empty;
                UTF8Encoding encodepwd = new UTF8Encoding();
                Decoder Decode = encodepwd.GetDecoder();
                byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
                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);
                decryptpwd = new String(decoded_char);

                image = baseurl + "/" + decryptpwd + "." + extention;
            }
            else
            {
                image = "~/Users/Images/Chrysanthemum.jpg";
            }
            return image;
        }
Esempio n. 2
0
        /// <summary>
        /// Decodeaza textul din base 64
        /// </summary>
        /// <param name="text">Textul</param>
        /// <param name="deviation">Adevarat daca textul este deviat</param>
        /// <returns></returns>
        public static string DecodeBase64(string text, bool deviation)
        {
            try
            {
                var encoder = new UTF8Encoding();
                Decoder utf8Decode = encoder.GetDecoder();

                if (deviation)
                {
                    // lungimea initiala a textului codat (dupa %)
                    int initialLength;
                    int indexOf = text.LastIndexOf('%');
                    int.TryParse(text.Substring(indexOf + 1), out initialLength);
                    text = Deviate(text.Substring(0, indexOf), -initialLength);
                }

                byte[] todecode_byte = Convert.FromBase64String(text);
                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)
            {
                return "";
            }
        }
Esempio n. 3
0
        /// <summary>
        /// based on http://weblogs.asp.net/abdullaabdelhaq/archive/2009/06/27/displaying-arabic-number.aspx
        /// seems like a fairly expensive method to call so not sure if its suitable to use this everywhere
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static string SubstituteArabicDigits(string input)
        {
            if (string.IsNullOrEmpty(input)) { return input; }

            Encoding utf8 = new UTF8Encoding();
            Decoder utf8Decoder = utf8.GetDecoder();
            StringBuilder result = new StringBuilder();

            Char[] translatedChars = new Char[1];
            Char[] inputChars = input.ToCharArray();
            Byte[] bytes = { 217, 160 };

            foreach (Char c in inputChars)
            {
                if (Char.IsDigit(c))
                {
                    // is this the key to it all? does adding 160 change to the unicode char for Arabic?
                    //So we can do the same with other languages using a different offset?
                    bytes[1] = Convert.ToByte(160 + Convert.ToInt32(char.GetNumericValue(c)));
                    utf8Decoder.GetChars(bytes, 0, 2, translatedChars, 0);
                    result.Append(translatedChars[0]);
                }
                else
                {
                    result.Append(c);
                }
            }

            return result.ToString();
        }
Esempio n. 4
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];

                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);

                string result = new String(decoded_char);

                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("Error in base64Decode" + ex.Message);
            }
        }
Esempio n. 5
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];

            utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);

            string result = new String(decoded_char);

            return(result);
        }
        catch (Exception ex)
        {
            throw new Exception("Error in base64Decode" + ex.Message);
        }
    }
        private string ConvertToArabicNumerals(string input)
        {
            UTF8Encoding utf8Encoder = new UTF8Encoding();
            Decoder utf8Decoder = utf8Encoder.GetDecoder();
            StringBuilder convertedChars = new System.Text.StringBuilder();
            char[] convertedChar = new char[1];
            byte[] bytes = new byte[] { 217, 160 };
            char[] inputCharArray = input.ToCharArray();

            foreach (char c in inputCharArray)
            {
                if (char.IsDigit(c))
                {
                    bytes[1] = System.Convert.ToByte(160 + char.GetNumericValue(c));
                    utf8Decoder.GetChars(bytes, 0, 2, convertedChar, 0);
                    convertedChars.Append(convertedChar[0]);
                }
                else
                {
                    convertedChars.Append(c);
                }
            }

            return convertedChars.ToString();
        }
Esempio n. 7
0
    public static string decryptPassword1(string sData)
    {
        string result = "";
        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);

            result = new string(decoded_char);

        }
        catch
        {

        }
        return result;
    }
Esempio n. 8
0
        public static string Decode( string data )
        {
            UTF8Encoding encoder = new UTF8Encoding( );
            Decoder utf8Decode = encoder.GetDecoder( );

            byte[ ] todecode_byte = Convert.FromBase64String( data );

            return Decode( todecode_byte );
        }
Esempio n. 9
0
 public static string DecodeBase64String(string encodedString)
 {
     byte[] bytes = Convert.FromBase64String(encodedString);
     var encoder = new UTF8Encoding();
     Decoder decoder = encoder.GetDecoder();
     int charCount = decoder.GetCharCount(bytes, 0, bytes.Length);
     var decodedMessage = new char[charCount];
     decoder.GetChars(bytes, 0, bytes.Length, decodedMessage, 0);
     return new string(decodedMessage);
 }
Esempio n. 10
0
    public string base64Decode(string sData)
    {
        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);
    }
 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;
 }
Esempio n. 12
0
        public string Decrypts(string cipherString, bool useHashing)
        {
            //space replace to "+"
            cipherString = cipherString.Replace(" ", "+");

            byte[] keyArray;
            byte[] toEncryptArray = Convert.FromBase64String(cipherString);

            //System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
            //Get your key from config file to open the lock!
            string key = "dinoosys@!@#";

            if (useHashing)
            {
                MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
                keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
                hashmd5.Clear();
            }
            else
            {
                keyArray = UTF8Encoding.UTF8.GetBytes(key);
            }

            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

            tdes.Key     = keyArray;
            tdes.Mode    = CipherMode.ECB;
            tdes.Padding = PaddingMode.PKCS7;

            ICryptoTransform cTransform = tdes.CreateDecryptor();

            byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

            tdes.Clear();
            return(UTF8Encoding.UTF8.GetString(resultArray));

            string ResultString = string.Empty;

            try
            {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();
                byte[] todecode_byte = Convert.FromBase64String(cipherString);
                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);
                ResultString = new String(decoded_char);
            }
            catch (Exception ex)
            {
                throw new Exception("invalid result.");
            }
            return(ResultString);
        }
Esempio n. 13
0
        public static string MyDecrypt(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));
        }
Esempio n. 14
0
    /// <summary>
    /// Event, that triggers when the application page is loaded into the web browser
    /// Listens to server and stores the mms messages in server
    /// </summary>
    /// <param name="sender">object, that caused this event</param>
    /// <param name="e">Event that invoked this function</param>
    protected void Page_Load(object sender, EventArgs e)
    {
        FileStream fileStream = null;
        try
        {
            Random random = new Random();
            DateTime currentServerTime = DateTime.UtcNow;

            string receivedTime = currentServerTime.ToString("HH-MM-SS");
            string receivedDate = currentServerTime.ToString("MM-dd-yyyy");

            string inputStreamContents;
            int stringLength;
            int strRead;

            Stream stream = Request.InputStream;
            stringLength = Convert.ToInt32(stream.Length);

            byte[] stringArray = new byte[stringLength];
            strRead = stream.Read(stringArray, 0, stringLength);
            inputStreamContents = System.Text.Encoding.UTF8.GetString(stringArray);

            string[] splitData = Regex.Split(inputStreamContents, "</SenderAddress>");
            string data = splitData[0].ToString();
            string senderAddress = inputStreamContents.Substring(data.IndexOf("tel:") + 4, data.Length - (data.IndexOf("tel:") + 4));
            string[] parts = Regex.Split(inputStreamContents, "--Nokia-mm-messageHandler-BoUnDaRy");
            string[] lowerParts = Regex.Split(parts[2], "BASE64");
            string[] imageType = Regex.Split(lowerParts[0], "image/");
            int indexOfSemicolon = imageType[1].IndexOf(";");
            string type = imageType[1].Substring(0, indexOfSemicolon);
            UTF8Encoding encoder = new System.Text.UTF8Encoding();
            Decoder utf8Decode = encoder.GetDecoder();

            byte[] todecode_byte = Convert.FromBase64String(lowerParts[1]);

            if (!Directory.Exists(Request.MapPath(ConfigurationManager.AppSettings["ImageDirectory"])))
            {
                Directory.CreateDirectory(Request.MapPath(ConfigurationManager.AppSettings["ImageDirectory"]));
            }

            string fileNameToSave = "From_" + senderAddress.Replace("+","") + "_At_" + receivedTime + "_UTC_On_" + receivedDate + random.Next();
            fileStream = new FileStream(Request.MapPath(ConfigurationManager.AppSettings["ImageDirectory"]) + fileNameToSave + "." + type, FileMode.CreateNew, FileAccess.Write);
            fileStream.Write(todecode_byte, 0, todecode_byte.Length);
        }
        catch
        { }
        finally
        {
            if (null != fileStream)
            {
                fileStream.Close();
            }
        }
    }
    public string Url_Decodificada(string cadena)
    {
        var encoder = new System.Text.UTF8Encoding();
        var utf8Decode = encoder.GetDecoder();

        byte[] cadenaByte = Convert.FromBase64String(cadena);
        int charCount = utf8Decode.GetCharCount(cadenaByte, 0, cadenaByte.Length);
        char[] decodedChar = new char[charCount];
        utf8Decode.GetChars(cadenaByte, 0, cadenaByte.Length, decodedChar, 0);
        string result = new String(decodedChar);
        return result;
    }
Esempio n. 16
0
        public void Base64Decode()
        {
            var encoder = new System.Text.UTF8Encoding();
            var utf8Decode = encoder.GetDecoder();

            byte[] cadenaByte = Convert.FromBase64String(this.contenido);
            int charCount = utf8Decode.GetCharCount(cadenaByte, 0, cadenaByte.Length);
            char[] decodedChar = new char[charCount];
            utf8Decode.GetChars(cadenaByte, 0, cadenaByte.Length, decodedChar, 0);
            string result = new String(decodedChar);
            this.contenido = result;
        }
Esempio n. 17
0
 /// <summary>
 /// Function is used to Decrypt the password
 /// </summary>
 /// <param name="password"></param>
 /// <returns></returns>
 public static string DecryptPassword(string encryptedPassword)
 {
     //output
     System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
     System.Text.Decoder utf8Decode = encoder.GetDecoder();
     byte[] todecode_byte = Convert.FromBase64String(encryptedPassword);
     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;
 }
Esempio n. 18
0
File: XPay.cs Progetto: GNCPay/core
        String base64Decode(String data)
        {
            UTF8Encoding encoder = new System.Text.UTF8Encoding();
            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;
        }
Esempio n. 19
0
 private string Decryptdata(string encryptpwd)
 {
     string decryptpwd = string.Empty;
     UTF8Encoding encodepwd = new UTF8Encoding();
     Decoder Decode = encodepwd.GetDecoder();
     byte[] todecode_byte = Convert.FromBase64String(encryptpwd);
     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);
     decryptpwd = new String(decoded_char);
     return decryptpwd;
 }
Esempio n. 20
0
        public static string FromBase64String(string data)
        {
            var encoder = new UTF8Encoding();
            var utf8Decode = encoder.GetDecoder();

            var todecodeByte = Convert.FromBase64String(data);
            var 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;
        }
Esempio n. 21
0
        public dynamic Post(employee logininfo)
        {
            try
            {
                /* var encodedpass = db.employees.Where(u => (u.mobile == logininfo.mobile))
                 *   .Select(x => new { x.password }).FirstOrDefault();*/

                var user = (from emp in db.employees
                            where emp.mobile == logininfo.mobile
                            select emp.password).FirstOrDefault();
                var e = user;


                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);


                var tempUser = (from emp in db.employees
                                where emp.mobile == logininfo.mobile && pass == logininfo.password
                                select emp.name).FirstOrDefault();

                /* var tempUser = db.employees.Where(u => (u.mobile == logininfo.mobile &&
                 * pass == logininfo.password)).Select(x=>new {x.name }).FirstOrDefault();*/

                /* var tempUser = db.employees.FirstOrDefault(u => u.mobile== logininfo.mobile &&
                 * u.password==logininfo.password);*/


                /*   var userdata = db.LoginDetails
                 *        .Where(y => (y.Email == login.Email && y.Password == login.Password))
                 *        .Select(x => new { x.UserID, x.UserName });*/
                if (tempUser != null)
                {
                    return(this.Request.CreateResponse(HttpStatusCode.OK, tempUser));
                    //  return new Response {/* Status = "Success",*/ Message = logininfo.mail };
                }
                else
                {
                    return(this.Request.CreateResponse(HttpStatusCode.OK, "Invalid"));
                    //return new Response { /*Status = "loginfailed",*/Message = "Invalid" };
                }
            }

            catch (Exception e)
            {
                return(this.Request.CreateResponse(HttpStatusCode.OK, "Invalid"));
            }
        }
        public static string Decode( byte[ ] todecode_byte )
        {
            UTF8Encoding encoder = new UTF8Encoding( );
            Decoder utf8Decode = encoder.GetDecoder( );

            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 );
        }
Esempio n. 23
0
    public string DecryptCode(string code)
    {
        code = code.Substring(0, code.Length - 1);
        System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
        System.Text.Decoder      utf8Decode = encoder.GetDecoder();
        byte[] todecode_byte = Convert.FromBase64String(code);
        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);
        code = new String(decoded_char);
        return(code);
    }
Esempio n. 24
0
 static public int GetDecoder(IntPtr l)
 {
     try {
         System.Text.UTF8Encoding self = (System.Text.UTF8Encoding)checkSelf(l);
         var ret = self.GetDecoder();
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Esempio n. 25
0
        public static string Decrypt(string value)
        {
            UTF8Encoding encoder = new UTF8Encoding();
            Decoder utf8Decode = encoder.GetDecoder();

            byte[] todecode_byte = Convert.FromBase64String(value);
            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;
        }
        //and Decoding:

        public string DecoAndGetServerName(string Servername)
        {
            System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
            System.Text.Decoder      strDecoder = encoder.GetDecoder();
            byte[] to_DecodeByte = Convert.FromBase64String(Servername);
            int    charCount     = strDecoder.GetCharCount(to_DecodeByte, 0, to_DecodeByte.Length);

            char[] decoded_char = new char[charCount];
            strDecoder.GetChars(to_DecodeByte, 0, to_DecodeByte.Length, decoded_char, 0);
            string Name = new string(decoded_char);

            return(Name);
        }
        /// <summary>
        /// Decodes a base 64 string.
        /// </summary>
        /// <param name="value">The base 64 string.</param>
        /// <returns></returns>
        public static string FromBase64(this string value)
        {
            var encoder = new UTF8Encoding();
            var utf8Decode = encoder.GetDecoder();
            var toEncodeBytes = Convert.FromBase64String(value);

            var characterCount = utf8Decode.GetCharCount(toEncodeBytes, 0, toEncodeBytes.Length);
            var decodedCharacter = new char[characterCount];
            utf8Decode.GetChars(toEncodeBytes, 0, toEncodeBytes.Length, decodedCharacter, 0);

            var result = new String(decodedCharacter);
            return result;
        }
Esempio n. 28
0
        public void Base64Decode()
        {
            var encoder    = new System.Text.UTF8Encoding();
            var utf8Decode = encoder.GetDecoder();

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

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

            this.contenido = result;
        }
Esempio n. 29
0
        public static string Base64Decode(string cadena)
        {
            var encoder    = new System.Text.UTF8Encoding();
            var utf8Decode = encoder.GetDecoder();

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

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

            return(result);
        }
        public static string Decrypt(string password)
        {
            //----Decription For Password Logic Start
            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 pass = new String(decoded_char);

            //----End Decription For Password Logic
            return(pass);
        }
Esempio n. 31
0
        /// <summary>
        /// Creates a CodeReader for the given parameters.
        /// </summary>
        internal CodeReader(string keyPath, string codeFilePath)
        {
            // Open stream
            this._codeStream = File.Open(codeFilePath, FileMode.Open, FileAccess.Read);

            // Get protocol
            this._coder = Coder.GetCoder(CoderVersion.Fox, keyPath);
            this._protocol = Protocol.GetProtocol(this, keyPath);
            this._coder = this._protocol.Coder;

            // Get encoding to use
            Encoding encodingToUse = new UTF8Encoding();
            this._decoder = encodingToUse.GetDecoder();
            this._maxCharSize = encodingToUse.GetMaxCharCount(0x80);
        }
Esempio n. 32
0
        public static string Decode(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);
                return new String(decoded_char);
            }
            catch { }
            return "";
        }
Esempio n. 33
0
        /// Base 64 Decode
        public static string Base64Decode(string data)
        {
            try {
                UTF8Encoding encoder = new UTF8Encoding();
                Decoder utf8Decode = encoder.GetDecoder();

                byte[] toDecodeByte = Convert.FromBase64String(data);
                int chrCount = utf8Decode.GetCharCount(toDecodeByte, 0,
                                                        toDecodeByte.Length);
                char[] decodedChar = new char[chrCount];
                utf8Decode.GetChars(toDecodeByte, 0, toDecodeByte.Length,
                                    decodedChar, 0);
                return(new String(decodedChar));
            } catch {}
            return(null);
        }
        public static String Decode(string Path)
        {
            String text;
            using (StreamReader sr = new StreamReader(Path))
            {
                text = sr.ReadToEnd();
                byte[] bytes = Convert.FromBase64String(text);
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
                System.Text.Decoder decoder = encoder.GetDecoder();
                int count = decoder.GetCharCount(bytes, 0, bytes.Length);
                char[] arr = new char[count];
                decoder.GetChars(bytes, 0, bytes.Length, arr, 0);
                text = new string(arr);

                return text;
            }
        }
Esempio n. 35
0
 public string Base64Decode(string sData) //Decode
 {
     try
     {
         var encoder      = new System.Text.UTF8Encoding();
         var utf8Decode   = encoder.GetDecoder();
         var todecodeByte = Convert.FromBase64String(sData);
         var 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);
     }
     catch (Exception ex)
     {
         throw new Exception("Error in base64Decode" + ex.Message);
     }
 }
Esempio n. 36
0
 public static string GetBase64Decode(string data)
 {
     try
     {
         System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
         System.Text.Decoder utf8Decode = encoder.GetDecoder();
         byte[] byte_data = Convert.FromBase64String(data);
         int charCount = utf8Decode.GetCharCount(byte_data, 0, byte_data.Length);
         char[] decoded_char = new char[charCount];
         utf8Decode.GetChars(byte_data, 0, byte_data.Length, decoded_char, 0);
         string result = new String(decoded_char);
         return result;
     }
     catch (Exception e)
     {
         throw;
     }
 }
Esempio n. 37
0
 public static string Base64Decode(string data)
 {
     try
     {
         System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
         System.Text.Decoder      utf8Decode = encoder.GetDecoder();
         data = data.Replace("-", "+").Replace("_", "/");
         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)
     {
         return("");
     }
 }
Esempio n. 38
0
    String storeProfileImage(String _userImage, String _userID)
    {
        string profileImgURL = "";

        if (_userImage != "")
        {
            string sSavePath = "App_Resources/";
            System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decode = encoder.GetDecoder();
            byte[] ret = Convert.FromBase64String(_userImage);

            // Save the stream to disk
            System.IO.FileStream newFile = new System.IO.FileStream(Server.MapPath(sSavePath + _userID + ".jpg"), System.IO.FileMode.Create);
            newFile.Write(ret, 0, ret.Length);
            newFile.Close();
            profileImgURL = "http://192.168.69.1/MTutorService/App_Resources/" + _userID + ".jpg";
        }
        return(profileImgURL);
    }
Esempio n. 39
0
        private 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];
                utf8Decode.GetChars(todecode_byte, 0, todecode_byte.Length, decoded_char, 0);
                string result = new String(decoded_char);

                return(result);
            }
            catch
            {
                throw new InvalidCastException("Error decoding DB password");
            }
        }
Esempio n. 40
0
            public static string Decrypt(string cipherText, string passPhrasee = "ASD")
            {
                var rand = cipherText.Substring(0, 6);


                string passPhrase = passPhrasee;


                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();
                byte[] todecode_byte = Convert.FromBase64String(cipherText.Decode());
                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);
            }
Esempio n. 41
0
        /// <summary>
        /// Decodes a base64 string
        /// </summary>
        /// <param name="data">string that will be converted</param>
        /// <returns>true if the conversion succeeded or false if it didnt</returns>
        public static bool Base64StringDecode(string data)
        {
            try
            {
                System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
                System.Text.Decoder utf8Decode = encoder.GetDecoder();

                byte[] todecode_byte = System.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);
                data = new String(decoded_char);
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
Esempio n. 42
0
        /// <summary>
        /// Decodes a base64 string
        /// </summary>
        /// <param name="data">string that will be converted</param>
        /// <returns>true if the conversion succeeded or false if it didnt</returns>
        public static bool Base64StringDecode(string data)
        {
            try
            {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();

                byte[] todecode_byte = System.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);
                data = new String(decoded_char);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        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);
                Int32  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;
            }
        }
Esempio n. 44
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)
            {
                return string.Empty;
            }
        }
Esempio n. 45
0
 public static string base64Utf8Decode(string data)
 {
     string result = "";
     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);
         result = new String(decoded_char);
     }
     catch (Exception e)
     {
         //return "Error in base64Encode" + e.Message;
     }
     return result;
 }
Esempio n. 46
0
        public string decryptPassword(string sData)
        {
            System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decode = encoder.GetDecoder();
            int mod4 = sData.Length % 4;

            if (mod4 > 0)
            {
                sData += new string('=', 4 - mod4);
            }
            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);
        }
Esempio n. 47
0
 protected void Page_Load(object sender, EventArgs e)
 {
     //System.IO.File.WriteAllText(@"C:\Users\Public\TestFolder\WriteText.txt", text);
     Random random = new Random();
     DateTime currentServerTime = DateTime.UtcNow;
       string receivedTime = currentServerTime.ToString("HH-MM-SS");
     string receivedDate = currentServerTime.ToString("MM-dd-yyyy");
     string inputStreamContents;
     int stringLength;
     int strRead;
     System.IO.Stream str = Request.InputStream;
     stringLength = Convert.ToInt32(str.Length);
     byte[] stringArray = new byte[stringLength];
     strRead = str.Read(stringArray, 0, stringLength);
     inputStreamContents = System.Text.Encoding.UTF8.GetString(stringArray);
     string[] splitData = Regex.Split(inputStreamContents, "</SenderAddress>");
     string data=splitData[0].ToString();
     String senderAddress = inputStreamContents.Substring(data.IndexOf("tel:") + 4, data.Length - (data.IndexOf("tel:") + 4));
     String[] parts = Regex.Split(inputStreamContents,"--Nokia-mm-messageHandler-BoUnDaRy");
     String[] lowerParts = Regex.Split(parts[2],"BASE64");
     String[] imageType = Regex.Split(lowerParts[0], "image/");
     int indexOfSemicolon=imageType[1].IndexOf(";");
     string type = imageType[1].Substring(0,indexOfSemicolon);
     System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
     System.Text.Decoder utf8Decode = encoder.GetDecoder();
     byte[] todecode_byte = Convert.FromBase64String(lowerParts[1]);
     //Give Images directory as path example: @"D:\folder"
     if (Directory.Exists(@"D:\Webs\wincod\APIPlatform\2\0\1\PROD\Csharp-RESTful\mms\app3\MoImages\"))
     {
     }
     else
     {
         //Give Images directory as path example: @"D:\folder", same as above value
         System.IO.Directory.CreateDirectory(@"D:\Webs\wincod\APIPlatform\2\0\1\PROD\Csharp-RESTful\mms\app3\MoImages\");
     }
     string fileNameToSave = "From_" + senderAddress + "_At_" + receivedTime + "_UTC_On_" +  receivedDate + random.Next() ;
     //Give Images directory as first argument example: @"D:\folder", same as above value
     FileStream fs = new FileStream(@"D:\Webs\wincod\APIPlatform\2\0\1\PROD\Csharp-RESTful\mms\app3\MoImages\" + fileNameToSave + "." + type, FileMode.CreateNew, FileAccess.Write);
     fs.Write(todecode_byte, 0, todecode_byte.Length);
     fs.Close();
     //random.Next()
 }
Esempio n. 48
0
 protected string decodepwd(string depas)
 {
     try
     {
         System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
         System.Text.Decoder utf8Decode = encoder.GetDecoder();
         byte[] todecode_byte = Convert.FromBase64String(depas);
         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)
     {
         CreateLogFile log = new CreateLogFile();
         log.ErrorLog(Server.MapPath("Logs/Errorlog"), "Decode method of VerifyMail page :" + ex.Message);
         return "conversion error";
     }
 }
Esempio n. 49
0
 protected string decodepwd(string depas)
 {
     try
     {
         System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
         System.Text.Decoder      utf8Decode = encoder.GetDecoder();
         byte[] todecode_byte = Convert.FromBase64String(depas);
         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)
     {
         CreateLogFile log = new CreateLogFile();
         log.ErrorLog(Server.MapPath("../Logs/Errorlog"), "Decode method of AlumniProfileHome page for " + Session["loginname"] + ":" + ex.Message);
         return("conversion error");
     }
 }
Esempio n. 50
0
        public string base64Decode(string sData)
        {
            System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decode = encoder.GetDecoder();
            try
            {
                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 err)
            {
                //Response.Redirect("~/error.aspx");
                return("");
            }
        }
Esempio n. 51
0
        //public static string profileidEncrypt(string clearText)
        //{
        //    string EncryptionKey = "MAKV2SPBNI99212";
        //    byte[] clearBytes = Encoding.Unicode.GetBytes(clearText);
        //    using (Aes encryptor = Aes.Create())
        //    {
        //        Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
        //        encryptor.Key = pdb.GetBytes(32);
        //        encryptor.IV = pdb.GetBytes(16);

        //        using (MemoryStream ms = new MemoryStream())
        //        {
        //            using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateEncryptor(), CryptoStreamMode.Write))
        //            {
        //                cs.Write(clearBytes, 0, clearBytes.Length);
        //                cs.Close();
        //            }
        //            clearText = Convert.ToBase64String(ms.ToArray());
        //        }
        //    }

        //    return clearText;
        //}

        public static string base64Decode(string data)
        {
            try
            {
                data = data.Replace("100", "=").Replace("200", "+").Replace("300", "#").Replace("400", "!").Replace("500", ";").Replace("600", "'").Replace("700", "/").Replace("800", "\\");
                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);
            }
        }
Esempio n. 52
0
        public static string Base64Decode(string textToTransform)
        {
            try
            {
                byte[] toDecodeByte = Convert.FromBase64String(textToTransform);

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

                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);
            }
            catch
            {
                return "Invalid input: This does not seem to be a valid Base64 encoded string. Try adding an equals or two on the end ;)";
            }
        }
Esempio n. 53
0
        public string Decrypt(string asEncryptedString)
        {
            string result = null;

            try
            {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();
                byte[] todecode_byte = Convert.FromBase64String(asEncryptedString);
                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)
            {
                Logger.WriteError(Ex, "Decrypt", "User");
                throw Ex;
            }
            return(result);
        }
Esempio n. 54
0
        public string base64Decode(string data)
        {
            //siiani on töötanud
            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)
            {
                MessageBox.Show(e.ToString());
                throw new Exception("Error in base64Decode" + e.Message);
            }
        }
Esempio n. 55
0
        public static string Base64Decode(string Value)
        {
            try
            {
                System.Text.UTF8Encoding objEncoding    = new System.Text.UTF8Encoding();
                System.Text.Decoder      objUTF8Decoder = objEncoding.GetDecoder();

                byte[] arrBytes = Convert.FromBase64String(Value);
                return(objEncoding.GetString(arrBytes));

                //int charCount = objUTF8Decoder.GetCharCount(arrBytes, 0, arrBytes.Length);
                //char[] arrChars = new char[charCount];
                //objUTF8Decoder.GetChars(arrBytes, 0, arrBytes.Length, arrChars, 0);
                //return new String(arrChars);
            }
            catch (Exception ex)
            {
                ExceptionManager.Publish(ex);
                return("");
            }
        }
Esempio n. 56
0
        /// <summary>
        /// 解密。
        /// </summary>
        internal static string Decrypt(string pToDecrypt)
        {
            String Result = "";

            if (String.IsNullOrEmpty(pToDecrypt))
            {
                return(Result);
            }
            try {
                System.Text.UTF8Encoding encoder    = new System.Text.UTF8Encoding();
                System.Text.Decoder      utf8Decode = encoder.GetDecoder();
                byte[] todecode_byte = Convert.FromBase64String(pToDecrypt);
                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);
                return(Result);
            }
            catch {
                //throw new Exception("Error in base64Decode" + e.Message);
                return("");
            }

            /*DESCryptoServiceProvider provider = new DESCryptoServiceProvider();
             * byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
             * for (int x = 0; x < pToDecrypt.Length / 2; x++) {
             *      int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
             *      inputByteArray[x] = (byte)i;
             * }
             * provider.Key = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
             * provider.IV = Encoding.ASCII.GetBytes(FormsAuthentication.HashPasswordForStoringInConfigFile(sKey, "md5").Substring(0, 8));
             * MemoryStream ms = new MemoryStream();
             * CryptoStream cs = new CryptoStream(ms, provider.CreateDecryptor(), CryptoStreamMode.Write);
             * cs.Write(inputByteArray, 0, inputByteArray.Length);
             * cs.FlushFinalBlock();
             * Result= Encoding.Default.GetString(ms.ToArray());
             * cs.Close();
             * return Result;*/
        }
Esempio n. 57
0
        internal static string Base64Decode(string data)
        {
            string result = String.Empty;

            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);
                result = new String(decoded_char);
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
            }

            return result;
        }
Esempio n. 58
0
        public static string base64Decode(string sData) //Decode
        {
            try
            {
                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);
            }

            /*string EncryptionKey = "MAKV2SPBNI99212";
             * byte[] cipherBytes = Convert.FromBase64String(cipherText);
             * using (Aes encryptor = Aes.Create())
             * {
             *  Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(EncryptionKey, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
             *  encryptor.Key = pdb.GetBytes(32);
             *  encryptor.IV = pdb.GetBytes(16);
             *  using (MemoryStream ms = new MemoryStream())
             *  {
             *      using (CryptoStream cs = new CryptoStream(ms, encryptor.CreateDecryptor(), CryptoStreamMode.Write))
             *      {
             *          cs.Write(cipherBytes, 0, cipherBytes.Length);
             *          cs.Close();
             *      }
             *      cipherText = Encoding.Unicode.GetString(ms.ToArray());
             *  }
             * }
             * return cipherText;
             * //  }*/
            catch (Exception ex)
            {
                throw new Exception("Error in base64Decode" + ex.Message);
            }
        }
Esempio n. 59
0
        //this method will convert all english numbers in string into arabic format
        public static string TranslateNumerals(string sIn, bool IsDate)
        {
            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            System.Text.Decoder      utf8Decoder;
            utf8Decoder = enc.GetDecoder();
            StringBuilder sTranslated = new StringBuilder();

            char[] cTransChar = new char[1];
            byte[] bytes      = new byte[] { 217, 160 };
            char[] aChars     = sIn.ToCharArray();
            foreach (char c in aChars)
            {
                if (char.IsDigit(c))
                {
                    bytes[1] = Convert.ToByte(160 + Convert.ToInt32((char.GetNumericValue(c))));
                    utf8Decoder.GetChars(bytes, 0, 2, cTransChar, 0);
                    sTranslated.Append(cTransChar[0]);
                }
                else
                {
                    sTranslated.Append(c);
                }
            }
            if (IsDate)
            {
                string   finalResult = "";
                string[] strSplit    = sTranslated.ToString().Split(new char[] { '/' });
                for (int i = strSplit.Length - 1; i >= 0; i--)
                {
                    finalResult += strSplit[i] + "/";
                }
                return(finalResult.Substring(0, finalResult.Length - 1));
            }
            else
            {
                return(sTranslated.ToString());
            }
        }
Esempio n. 60
0
        public string SetDecoding(string strText)
        {
            string strReturn = null;

            do
            {
                try {
                    System.Text.UTF8Encoding objEncoding = new System.Text.UTF8Encoding();
                    System.Text.Decoder      objDecoder  = objEncoding.GetDecoder();

                    byte[] bDecode    = Convert.FromBase64String(strText);
                    int    iCount     = objDecoder.GetCharCount(bDecode, 0, bDecode.Length);
                    char[] charDecode = new char[iCount];
                    objDecoder.GetChars(bDecode, 0, bDecode.Length, charDecode, 0);
                    strReturn = new string( charDecode );
                }
                catch (Exception ex) {
                    Trace.WriteLine(ex.Message);
                }
            } while(false);

            return(strReturn);
        }