コード例 #1
0
        public static ValidationResponse ValidateByUpload(string validationData, string encodingType = "UNICODE_ENCODING")
        {
            #region Data encoding
            byte[] encodedValidationDataByteArr;
            if (encodingType == UNICODE_ENCODING)
            {
                // Use Unicode encoding
                UnicodeEncoding encodedValidationData = new UnicodeEncoding();
                encodedValidationDataByteArr = encodedValidationData.GetBytes(validationData);
            }
            else if (encodingType == ASCII_ENCODING)
            {
                // Use ASCII (7-bit) encoding
                ASCIIEncoding encodedValidationData = new ASCIIEncoding();
                encodedValidationDataByteArr = encodedValidationData.GetBytes(validationData);
            }
            else if (encodingType == UTF7_ENCODING)
            {
                // Use UTF-7 encoding
                UTF7Encoding encodedValidationData = new UTF7Encoding();
                encodedValidationDataByteArr = encodedValidationData.GetBytes(validationData);
            }
            else if (encodingType == UTF8_ENCODING)
            {
                // Use UTF-8 encoding
                UTF8Encoding encodedValidationData = new UTF8Encoding();
                encodedValidationDataByteArr = encodedValidationData.GetBytes(validationData);
            }
            else if (encodingType == UTF32_ENCODING)
            {
                // Use UTF-32 encoding
                UTF32Encoding encodedValidationData = new UTF32Encoding();
                encodedValidationDataByteArr = encodedValidationData.GetBytes(validationData);
            }
            else
            {
                throw new InvalidEncodingException("An invalid encoding type was specified. Type: " + encodingType);
            }
            #endregion

            #region Request formation
            HttpWebRequest uploadRequest = HttpWebRequest.CreateHttp(VALIDATOR_URL + VALIDATOR_URL_GET_ROOT + VALIDATOR_URL_GET_TYPE);
            uploadRequest.Method        = REQUEST_METHOD;
            uploadRequest.ContentType   = CONTENT_TYPE;
            uploadRequest.ContentLength = encodedValidationDataByteArr.Length;
            Stream uploadRequestStream = uploadRequest.GetRequestStream();
            uploadRequestStream.Write(encodedValidationDataByteArr, 0, encodedValidationDataByteArr.Length);
            #endregion

            // Make request
            // Stores response object in `uploadRequestResponse`
            HttpWebResponse uploadRequestResponse = (HttpWebResponse)uploadRequest.GetResponse();

            // Get response data
            Stream       uploadRequestResponseStream       = uploadRequestResponse.GetResponseStream();
            StreamReader uploadRequestResponseStreamReader = new StreamReader(uploadRequestResponseStream);
            string       uploadRequestResponseString       = uploadRequestResponseStreamReader.ReadToEnd();

            ValidationResponse response = ParseValidationResponse(uploadRequestResponseString);
        }
コード例 #2
0
        private string generarSHA1(string cadena)
        {
            UTF32Encoding enc = new UTF32Encoding();

            byte[] data = enc.GetBytes(cadena);
            byte[] result;

            //Convierte el string en SHA1 y asi poder cargarlo en la base de datos ya cifrada y no se pueda visualizar cual es la
            //contrasena del usuario
            SHA1CryptoServiceProvider sha = new SHA1CryptoServiceProvider();

            result = sha.ComputeHash(data);

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < result.Length; i++)
            {
                if (result[i] < 16)
                {
                    sb.Append("0");
                }

                sb.Append(result[i].ToString("X"));
            }
            return(sb.ToString());
        }
コード例 #3
0
        public void Json_text_with_different_encoding_should_be_interoperated()
        {
            var json = JsonSerializer.ToJson(new { Email = "*****@*****.**", Name = "san" });

            Assert.IsTrue(JsonValidator.IsValid(json));
            Assert.AreEqual("{\"Email\":\"[email protected]\",\"Name\":\"san\"}", json);

            //encoding without bom
            var utf32      = new UTF32Encoding(false, false);
            var utf16      = new UnicodeEncoding(false, false);
            var utf8       = new UTF8Encoding(false);
            var utf32Bytes = utf32.GetBytes(json);
            var utf16Bytes = utf16.GetBytes(json);

            //Direct reading of other byte streams, failed
            var utf32String = utf8.GetString(utf32Bytes);
            var utf16String = utf8.GetString(utf16Bytes);

            Assert.AreNotEqual(utf32String, json);
            Assert.AreNotEqual(utf16String, json);

            //Convert byte stream, successful
            var utf8Bytes = Encoding.Convert(utf16, utf8, utf16Bytes);

            utf16String = utf8.GetString(utf8Bytes);
            Assert.AreEqual(json, utf16String);

            utf8Bytes   = Encoding.Convert(utf32, utf8, utf32Bytes);
            utf32String = utf8.GetString(utf8Bytes);
            Assert.AreEqual(json, utf32String);
        }
コード例 #4
0
ファイル: encoding.utf32.1.cs プロジェクト: zhimaqiao51/docs
    public static void Main()
    {
        Encoding enc   = new UTF32Encoding(false, true, true);
        string   value = "\u00C4 \uD802\u0033 \u00AE";

        try {
            byte[] bytes = enc.GetBytes(value);
            foreach (var byt in bytes)
            {
                Console.Write("{0:X2} ", byt);
            }
            Console.WriteLine();

            string value2 = enc.GetString(bytes);
            Console.WriteLine(value2);
        }
        catch (EncoderFallbackException e) {
            Console.WriteLine("Unable to encode {0} at index {1}",
                              e.IsUnknownSurrogate() ?
                              String.Format("U+{0:X4} U+{1:X4}",
                                            Convert.ToUInt16(e.CharUnknownHigh),
                                            Convert.ToUInt16(e.CharUnknownLow)) :
                              String.Format("U+{0:X4}",
                                            Convert.ToUInt16(e.CharUnknown)),
                              e.Index);
        }
    }
コード例 #5
0
        private static int GetUnicodeNumber(char character)
        {
            var encoding = new UTF32Encoding();
            var bytes    = encoding.GetBytes(character.ToString().ToCharArray());

            return(BitConverter.ToInt32(bytes, 0));
        }
コード例 #6
0
        public static StringBuilder?GetTwitterEmojiUrl(this string emojiString)
        {
            var enc   = new UTF32Encoding(true, false);
            var bytes = enc.GetBytes(emojiString);

            var sbCodepointEmoji = new StringBuilder();

            for (var i = 0; i < bytes.Length; i += 4)
            {
                var value = bytes[i] << 24 | bytes[i + 1] << 16 | bytes[i + 2] << 8 | bytes[i + 3];
                if (value == 0xFE0E || value == 0xFE0F)
                {
                    continue;
                }
                sbCodepointEmoji.Append($"{value:x}-");
            }

            if (sbCodepointEmoji.Length > 0 && sbCodepointEmoji[^ 1] == '-')
            {
                sbCodepointEmoji.Remove(sbCodepointEmoji.Length - 1, 1);
            }

            if (sbCodepointEmoji.Length == 0)
            {
                return(null);
            }

            sbCodepointEmoji.Insert(0, "//cdn.jsdelivr.net/gh/twitter/twemoji/assets/svg/");
            sbCodepointEmoji.Append(".svg");
            return(sbCodepointEmoji);
        }
コード例 #7
0
    public static void Main()
    {
        // Create a UTF32Encoding object with error detection enabled.
        var encExc = new UTF32Encoding(!BitConverter.IsLittleEndian, true, true);
        // Create a UTF32Encoding object with error detection disabled.
        var encRepl = new UTF32Encoding(!BitConverter.IsLittleEndian, true, false);

        // Create a byte arrays from a string, and add an invalid surrogate pair, as follows.
        //    Latin Small Letter Z (U+007A)
        //    Latin Small Letter A (U+0061)
        //    Combining Breve (U+0306)
        //    Latin Small Letter AE With Acute (U+01FD)
        //    Greek Small Letter Beta (U+03B2)
        //    a high-surrogate value (U+D8FF)
        //    an invalid low surrogate (U+01FF)
        String s = "za\u0306\u01FD\u03B2";

        // Encode the string using little-endian byte order.
        int index = encExc.GetByteCount(s);

        Byte[] bytes = new Byte[index + 4];
        encExc.GetBytes(s, 0, s.Length, bytes, 0);
        bytes[index]     = 0xFF;
        bytes[index + 1] = 0xD8;
        bytes[index + 2] = 0xFF;
        bytes[index + 3] = 0x01;

        // Decode the byte array with error detection.
        Console.WriteLine("Decoding with error detection:");
        PrintDecodedString(bytes, encExc);

        // Decode the byte array without error detection.
        Console.WriteLine("Decoding without error detection:");
        PrintDecodedString(bytes, encRepl);
    }
コード例 #8
0
ファイル: Util.cs プロジェクト: IreneGigabit/nOpt
    /// <summary>
    /// 取得CharCode(支援罕字)
    /// </summary>
    public static int GetCharCode(this string character)
    {
        UTF32Encoding encoding = new UTF32Encoding();

        byte[] bytes = encoding.GetBytes(character.ToCharArray());
        return(BitConverter.ToInt32(bytes, 0));
    }
コード例 #9
0
        public static string Encrypt(string strTextToEncrypt)
        {
            System.Text.UTF32Encoding u  = new UTF32Encoding();
            MD5CryptoServiceProvider  md = new MD5CryptoServiceProvider();

            return(Convert.ToBase64String(md.ComputeHash(u.GetBytes(strTextToEncrypt))));
        }
コード例 #10
0
        public static string Encrypt(string strTextToEncrypt)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();

            System.Text.UTF32Encoding u = new UTF32Encoding();
            return(Convert.ToBase64String(rsa.Encrypt(u.GetBytes(strTextToEncrypt), false)));//a string
        }
コード例 #11
0
        /// <summary>
        /// Update User repository
        /// </summary>
        /// <param name="obj"></param>
        public bool Update(object obj)
        {
            User   updatedUser = Newtonsoft.Json.JsonConvert.DeserializeObject <User>(obj.ToString());
            string pass        = "";

            using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()){
                UTF32Encoding utf32 = new UTF32Encoding();
                byte[]        data  = md5.ComputeHash(utf32.GetBytes(updatedUser.pass));
                pass = Convert.ToBase64String(data);
            }

            string mySqlCommand = "update movieinfo "
                                  + "set"
                                  + " movieID = \"" + updatedUser.email + "\""
                                  + ",pass=\"" + pass + "\""
                                  + " where userID = " + updatedUser.userId + ";";

            // Execute command
            try
            {
                DatabaseManager.GetInstance.sqlCommand(mySqlCommand).ExecuteNonQuery();
                return(true);
            }
            catch (Exception err)
            {
                Console.WriteLine(err);
                return(false);
            }
        }
コード例 #12
0
        /// <summary>
        /// Creating a new user
        /// </summary>
        /// <param name="newObject"></param>
        public bool Create(object obj)
        {
            User newUser = Newtonsoft.Json.JsonConvert.DeserializeObject <User>(obj.ToString());

            string pass = "";

            using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()){
                UTF32Encoding utf32 = new UTF32Encoding();
                byte[]        data  = md5.ComputeHash(utf32.GetBytes(newUser.pass));
                pass = Convert.ToBase64String(data);
            }
            string mySqlCommand = "insert users (email, pass) value(";

            mySqlCommand += "\"" + newUser.email + "\","
                            + "\"" + pass + "\");";
            try
            {
                // executing the sql command
                DatabaseManager.GetInstance.sqlCommand(mySqlCommand).ExecuteNonQuery();
                return(true);
            }
            catch
            {
                Console.WriteLine("User is already existed can't add");
                return(false);
            }
        }
コード例 #13
0
ファイル: SignIn.cs プロジェクト: munsif3/ITP_NAKSSIUM
 public static String Encript(String value)
 {
     using (MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider()){
         UTF32Encoding utf8 = new UTF32Encoding();
         byte []       data = md5.ComputeHash(utf8.GetBytes(value));
         return(Convert.ToBase64String(data));
     }
 }
コード例 #14
0
ファイル: function.cs プロジェクト: AnhThi/Mens-Shop
 public static string Mahoa(string chuoi)
 {
     UTF32Encoding u = new UTF32Encoding();
     byte[] b = u.GetBytes(chuoi);
     MD5 s = new MD5CryptoServiceProvider();
     byte[] kq = s.ComputeHash(b);
     return Convert.ToBase64String(kq);
 }
コード例 #15
0
    private static int getUnicodeCode(char character)
    {
        UTF32Encoding encoding = new UTF32Encoding();
        byte[] bytes = encoding.GetBytes(character.ToString().ToCharArray());

        //return BitConverter.ToInt32(bytes, 0).ToString("X");
        return BitConverter.ToInt32(bytes, 0);
    }
コード例 #16
0
        private static int getUnicodeCode(char character)
        {
            UTF32Encoding encoding = new UTF32Encoding();

            byte[] bytes = encoding.GetBytes(character.ToString().ToCharArray());

            return(BitConverter.ToInt32(bytes, 0));
        }
コード例 #17
0
ファイル: XmlHelper.cs プロジェクト: mks786/CallCenter-1
    public static Byte[] StringToUTF8ByteArray(string pXmlString)
    {
        //UTF8Encoding encoding = new UTF8Encoding();
        UTF32Encoding encoding = new UTF32Encoding();

        byte[] byteArray = encoding.GetBytes(pXmlString);
        return(byteArray);
    }
コード例 #18
0
        public int ConvertGlyphToUnicodeNumber(string singleGlyph)
        {
            Encoding enc = new UTF32Encoding(false, true, true); byte[] b = enc.GetBytes(singleGlyph);

            Int32 index = BitConverter.ToInt32(b, 0);

            return(index);
        }
コード例 #19
0
        private static GraceObject mBEndian(EvaluationContext ctx,
                                            MethodRequest req,
                                            UTF32CodepointsView self)
        {
            var enc = new UTF32Encoding(true, false);

            return(new ByteString(enc.GetBytes(self.stringData)));
        }
コード例 #20
0
        public static string get_uft32(string unicodeString)
        {
            UTF32Encoding utf32 = new UTF32Encoding();

            Byte[] encodedBytes  = utf32.GetBytes(unicodeString);
            String decodedString = utf32.GetString(encodedBytes);

            return(decodedString);
        }
コード例 #21
0
ファイル: Hashing.cs プロジェクト: TheSniper102/winformsTuts
        private void button1_Click(object sender, EventArgs e)
        {
            MD5CryptoServiceProvider md5  = new MD5CryptoServiceProvider();
            UTF32Encoding            utf8 = new UTF32Encoding();
            string hashResult             = BitConverter.ToString(md5.ComputeHash(utf8.GetBytes(textBox1.Text)));

            label1.Text = hashResult;
            label2.Text = hashResult.Length.ToString();
        }
コード例 #22
0
ファイル: Hashing.cs プロジェクト: TheSniper102/winformsTuts
        private void button2_Click(object sender, EventArgs e)
        {
            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
            UTF32Encoding             utf8 = new UTF32Encoding();
            string hashResult = BitConverter.ToString(sha1.ComputeHash(utf8.GetBytes(textBox2.Text)));

            label4.Text = hashResult;
            label3.Text = hashResult.Length.ToString();
        }
コード例 #23
0
        public static string MaHoaMD5(string text)
        {
            UTF32Encoding            utf  = new UTF32Encoding();
            MD5CryptoServiceProvider mcsp = new MD5CryptoServiceProvider();

            byte[] bit1 = utf.GetBytes(text);
            byte[] bit2 = mcsp.ComputeHash(bit1);
            return(Convert.ToBase64String(bit2));
        }
コード例 #24
0
ファイル: function.cs プロジェクト: AnhThi/Mens-Shop
    public static string Mahoa(string chuoi)
    {
        UTF32Encoding u = new UTF32Encoding();

        byte[] b = u.GetBytes(chuoi);
        MD5    s = new MD5CryptoServiceProvider();

        byte[] kq = s.ComputeHash(b);
        return(Convert.ToBase64String(kq));
    }
コード例 #25
0
        public static string EncryptPassword(string Email, string Password)
        {
            string        encryptedPass = string.Empty;
            SHA256Managed hashedPass    = new SHA256Managed();

            byte[]        hashedbytes;
            UTF32Encoding passEncoder = new UTF32Encoding();

            hashedbytes   = hashedPass.ComputeHash(passEncoder.GetBytes(Password + Email));
            encryptedPass = Convert.ToBase64String(hashedbytes);
            return(encryptedPass);
        }
コード例 #26
0
        private static string MaHoaMD5(string password)
        {
            UTF32Encoding utf32    = new UTF32Encoding();
            string        keyMaHoa = string.Format("{0}", password);

            byte[] bytes = utf32.GetBytes(keyMaHoa);
            SHA1   md    = new SHA1CryptoServiceProvider();
            MD5    md5   = new MD5CryptoServiceProvider();

            byte[] kq  = md.ComputeHash(bytes);
            byte[] kq2 = md5.ComputeHash(kq);
            return(Convert.ToBase64String(kq2));
        }
コード例 #27
0
ファイル: EmojiUtils.cs プロジェクト: Djoe-Denne/Message2.0
        public string EmojiFile(String character)
        {
            Encoding enc      = new UTF32Encoding(true, false);
            String   fileName = string.Empty;

            if (character != "‍♂️" && character != "‍♀️")
            {
                byte[] bytes = enc.GetBytes(character);

                if (bytes.Length < 4)
                {
                    return("");
                }

                string charHexCode = BitConverter.ToString(bytes).Replace("-", "");

                while (charHexCode.ElementAt(0) == '0')
                {
                    charHexCode = charHexCode.Remove(0, 1);
                }

                if (charHexCode == String.Empty)
                {
                    return("");
                }

                charHexCode = charHexCode.ToLower();

                fileName = String.Format(".\\Emoji\\emoji_u{0}.png", charHexCode);

                if (!File.Exists(fileName))
                {
                    currentEmojiCode += currentEmojiCode == String.Empty ? charHexCode : "_" + charHexCode;
                }
                else if (currentEmojiCode == String.Empty)
                {
                    currentEmojiCode = "";
                }
            }
            else if (character == "‍♂️")
            {
                fileName         = String.Format(".\\Emoji\\emoji_u{0}_200d_2642.png", currentEmojiCode);
                currentEmojiCode = String.Empty;
            }
            else if (character == "‍♀️")
            {
                fileName         = String.Format(".\\Emoji\\emoji_u{0}_200d_2640.png", currentEmojiCode);
                currentEmojiCode = String.Empty;
            }
            return(File.Exists(fileName) ? fileName: String.Empty);
        }
コード例 #28
0
ファイル: getpreamble1.cs プロジェクト: zhimaqiao51/docs
    public static void Main()
    {
        String s = "This is a string to write to a file using UTF-32 encoding.";

        // Write a file using the default constructor without a BOM.
        var enc = new UTF32Encoding(!BitConverter.IsLittleEndian, false);

        Byte[] bytes = enc.GetBytes(s);
        WriteToFile(@".\NoPreamble.txt", enc, bytes);

        // Use BOM.
        enc = new UTF32Encoding(!BitConverter.IsLittleEndian, true);
        WriteToFile(@".\Preamble.txt", enc, bytes);
    }
コード例 #29
0
    public static void Main()
    {
        // Create two instances of UTF32Encoding: one with little-endian byte order and one with big-endian byte order.
        UTF32Encoding u32LE = new UTF32Encoding(false, true, true);
        UTF32Encoding u32BE = new UTF32Encoding(true, true, true);


        // Create byte arrays from the same string containing the following characters:
        //    Latin Small Letter Z (U+007A)
        //    Latin Small Letter A (U+0061)
        //    Combining Breve (U+0306)
        //    Latin Small Letter AE With Acute (U+01FD)
        //    Greek Small Letter Beta (U+03B2)
        //    a high-surrogate value (U+D8FF)
        //    a low-surrogate value (U+DCFF)
        String myStr = "za\u0306\u01FD\u03B2\uD8FF\uDCFF";

        // barrBE uses the big-endian byte order.
        byte[] barrBE = new byte[u32BE.GetByteCount(myStr)];
        u32BE.GetBytes(myStr, 0, myStr.Length, barrBE, 0);

        // barrLE uses the little-endian byte order.
        byte[] barrLE = new byte[u32LE.GetByteCount(myStr)];
        u32LE.GetBytes(myStr, 0, myStr.Length, barrLE, 0);


        // Get the char counts and decode the byte arrays.
        Console.Write("BE array with BE encoding : ");
        PrintCountsAndChars(barrBE, u32BE);
        Console.Write("LE array with LE encoding : ");
        PrintCountsAndChars(barrLE, u32LE);


        // Decode the byte arrays using an encoding with a different byte order.
        Console.Write("BE array with LE encoding : ");
        try  {
            PrintCountsAndChars(barrBE, u32LE);
        }
        catch (System.ArgumentException e)  {
            Console.WriteLine(e.Message);
        }

        Console.Write("LE array with BE encoding : ");
        try  {
            PrintCountsAndChars(barrLE, u32BE);
        }
        catch (System.ArgumentException e)  {
            Console.WriteLine(e.Message);
        }
    }
コード例 #30
0
        public static string Cifrar(string Contenido, string Clave)
        {
            var encoding = new UTF32Encoding();
            var cripto   = new RijndaelManaged();

            byte[] cifrado, retorno, key = GetKey(Clave);
            cripto.Key = key;
            cripto.GenerateIV();
            byte[] aEncriptar = encoding.GetBytes(Contenido);
            cifrado = cripto.CreateEncryptor().TransformFinalBlock(aEncriptar, 0, aEncriptar.Length);
            retorno = new byte[cripto.IV.Length + cifrado.Length];
            cripto.IV.CopyTo(retorno, 0);
            cifrado.CopyTo(retorno, cripto.IV.Length);
            return(Convert.ToBase64String(retorno));
        }
コード例 #31
0
        // Returns a new array of Unicode code points (effectively
        // UTF-32 / UCS-4) representing the given UTF-16 string.
        private static int[] ToCodePoints(string s)
        {
            bool     useBigEndian = !BitConverter.IsLittleEndian;
            Encoding utf32        = new UTF32Encoding(useBigEndian, false, true);

            byte[] octets = utf32.GetBytes(s);

            int[] result = new int[octets.Length / 4];
            for (int i = 0, j = 0; i < octets.Length; i += 4, j++)
            {
                result[j] = BitConverter.ToInt32(octets, i);
            }

            return(result);
        }
コード例 #32
0
ファイル: bom1.cs プロジェクト: zhimaqiao51/docs
    public static void Main()
    {
        // Create a UTF-32 encoding that supports a BOM.
        var enc = new UTF32Encoding();

        // A Unicode string with two characters outside an 8-bit code range.
        String s = "This Unicode string has 2 characters " +
                   "outside the ASCII range: \n" +
                   "Pi (\u03A0), and Sigma (\u03A3).";

        Console.WriteLine("Original string:");
        Console.WriteLine(s);
        Console.WriteLine();

        // Encode the string.
        Byte[] encodedBytes = enc.GetBytes(s);
        Console.WriteLine("The encoded string has {0} bytes.\n",
                          encodedBytes.Length);

        // Write the bytes to a file with a BOM.
        var fs = new FileStream(@".\UTF32Encoding.txt", FileMode.Create);

        Byte[] bom = enc.GetPreamble();
        fs.Write(bom, 0, bom.Length);
        fs.Write(encodedBytes, 0, encodedBytes.Length);
        Console.WriteLine("Wrote {0} bytes to the file.\n", fs.Length);
        fs.Close();

        // Open the file using StreamReader.
        var    sr        = new StreamReader(@".\UTF32Encoding.txt");
        String newString = sr.ReadToEnd();

        sr.Close();
        Console.WriteLine("String read using StreamReader:");
        Console.WriteLine(newString);
        Console.WriteLine();

        // Open the file as a binary file and decode the bytes back to a string.
        fs = new FileStream(@".\Utf32Encoding.txt", FileMode.Open);
        Byte[] bytes = new Byte[fs.Length];
        fs.Read(bytes, 0, (int)fs.Length);
        fs.Close();

        String decodedString = enc.GetString(encodedBytes);

        Console.WriteLine("Decoded bytes from binary file:");
        Console.WriteLine(decodedString);
    }