Ejemplo n.º 1
0
        public string GetCurrentGameInstall(string GameLocation)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            DirectoryInfo dInfo = new DirectoryInfo(Path.Combine(GameLocation, "projects", "lol_game_client", "filearchives"));
            DirectoryInfo[] subdirs = null;
            try
            {
                subdirs = dInfo.GetDirectories();
            }
            catch { return "0.0.0.0"; }
            string latestVersion = "0.0.1";
            foreach (DirectoryInfo info in subdirs)
            {
                latestVersion = info.Name;
            }

            string ParentDirectory = Directory.GetParent(GameLocation).FullName;
            Copy(Path.Combine(ParentDirectory, "Config"), Path.Combine(Client.ExecutingDirectory, "Config"));

            Copy(Path.Combine(GameLocation, "projects", "lol_game_client"), Path.Combine(Client.ExecutingDirectory, "RADS", "projects", "lol_game_client"));
            File.Copy(Path.Combine(GameLocation, "RiotRadsIO.dll"), Path.Combine(Client.ExecutingDirectory, "RADS", "RiotRadsIO.dll"));

            var VersionAIR = File.Create(Path.Combine("RADS", "VERSION_LOL"));
            VersionAIR.Write(encoding.GetBytes(latestVersion), 0, encoding.GetBytes(latestVersion).Length);
            VersionAIR.Close();
            return latestVersion;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 指定されたUIDを暗号化して返します。
        /// </summary>
        /// <param name="uid">MUID</param>
        /// <returns></returns>
        public static string Encrypt(string uid)
        {
            var encryptStr = "";
            if (!string.IsNullOrEmpty(uid))
            {
                if (CheckMuid(uid))
                {
                    uid = uid.Replace(".", "");
                    if(uid.Length%2!=0)
                    {
                        uid = uid + "0";
                    }
                    var asciiEncoding = new System.Text.ASCIIEncoding();

                    for (int i = 0; i < uid.Length / 2; i++)
                    {
                        var subUid = uid.Substring(i * 2, 2);
                        encryptStr = encryptStr + subUid + ((asciiEncoding.GetBytes(uid.Substring(i * 2, 1))[0] + asciiEncoding.GetBytes(uid.Substring(i * 2 + 1, 1))[0]) % 15).ToString("x");
                    }
                    char[] arr = encryptStr.ToCharArray();
                    Array.Reverse(arr);
                    encryptStr = new string(arr);
                }
                else
                {
                    encryptStr = "00000";
                }
            }
            else
            {
                encryptStr = "00000";
            }
            return encryptStr;
        }
Ejemplo n.º 3
0
        public string GetCurrentAirInstall(string Location)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            DirectoryInfo dInfo = new DirectoryInfo(Location);
            DirectoryInfo[] subdirs = null;
            try
            {
                subdirs = dInfo.GetDirectories();
            }
            catch { return "0.0.0.0"; }
            string latestVersion = "0.0.1";
            foreach (DirectoryInfo info in subdirs)
            {
                latestVersion = info.Name;
            }

            string AirLocation = Path.Combine(Location, latestVersion, "deploy");
            if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "ClientLibCommon.dat")))
            {
                File.Copy(Path.Combine(AirLocation, "lib", "ClientLibCommon.dat"), Path.Combine(Client.ExecutingDirectory, "ClientLibCommon.dat"));
            }
            if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite")))
            {
                File.Copy(Path.Combine(AirLocation, "assets", "data", "gameStats", "gameStats_en_US.sqlite"), Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));
            }

            Copy(Path.Combine(AirLocation, "assets", "images", "abilities"), Path.Combine(Client.ExecutingDirectory, "Assets", "abilities"));
            Copy(Path.Combine(AirLocation, "assets", "images", "champions"), Path.Combine(Client.ExecutingDirectory, "Assets", "champions"));

            var VersionAIR = File.Create(Path.Combine("Assets", "VERSION_AIR"));
            VersionAIR.Write(encoding.GetBytes(latestVersion), 0, encoding.GetBytes(latestVersion).Length);
            VersionAIR.Close();
            return latestVersion;
        }
Ejemplo n.º 4
0
 private static string CreateToken(string message, string secret)
 {
     // don't allow null secrets
     secret = secret ?? "";
     var encoding = new System.Text.ASCIIEncoding();
     byte[] keyByte = encoding.GetBytes(secret);
     byte[] messageBytes = encoding.GetBytes(message);
     using (var hmacsha256 = new System.Security.Cryptography.HMACSHA256(keyByte))
     {
         byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
         return Convert.ToBase64String(hashmessage);
     }
 }
 public static string EncryptPassword(string password)
 {
     string secret = "";
     var encoding = new System.Text.ASCIIEncoding();
     byte[] keyByte = encoding.GetBytes(secret);
     byte[] messageBytes = encoding.GetBytes(password);
     string pwdEncript = "";
     using (var hmacsha256 = new HMACSHA256(keyByte))
     {
         byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
         pwdEncript = Convert.ToBase64String(hashmessage);
     }
     return pwdEncript;
 }
        private string GenerateSignature(IRestClient client, IRestRequest request)
        {
            var uri = client.BuildUri(request);
            var query = uri.Query;

            if (!string.IsNullOrEmpty(query))
                query = query.Substring(1);

            var encoding = new System.Text.ASCIIEncoding();
            var key = encoding.GetBytes(_apiKey);
            var myhmacsha256 = new HMACSHA256(key);
            var hashValue = myhmacsha256.ComputeHash(encoding.GetBytes(query));
            var hmac64 = Convert.ToBase64String(hashValue);
            return hmac64;
        }
Ejemplo n.º 7
0
		public string Post(Uri uri, NameValueCollection input)
		{
			ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
			WebRequest request = WebRequest.Create(uri);
			string strInput = GetInputString(input);
			
			request.Method = "POST";
			request.ContentType = "application/x-www-form-urlencoded";
			request.ContentLength = strInput.Length;
			
			Stream writeStream = request.GetRequestStream();
			System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
			byte[] bytes = encoding.GetBytes(strInput);
			writeStream.Write(bytes, 0, bytes.Length);
			writeStream.Close();

            using (WebResponse response = request.GetResponse())
            {
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader streamReader = new StreamReader(responseStream);
                    return streamReader.ReadToEnd();
                }
            }
		}
Ejemplo n.º 8
0
        public static bool sendmessage(MessageTypes type, string msg, ref byte[] data)
        {
            try
            {
                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                byte[] message = encoding.GetBytes(msg);
                int size = HEADERSIZE + message.Length;
                data = new byte[size];
                byte[] sizebyte = BitConverter.GetBytes(size);
                byte[] typebyte = BitConverter.GetBytes((int)type);
                Array.Copy(sizebyte, 0, data, LENGTHOFFSET, sizebyte.Length);
                Array.Copy(typebyte, 0, data, TYPEOFFSET, typebyte.Length);
                Array.Copy(message, 0, data, HEADERSIZE, message.Length);
            }
#if DEBUG
            catch (Exception ex)
            {
                Console.WriteLine("error processing: " + type.ToString() + " msg: " + msg + " err: " + ex.Message + ex.StackTrace);
                return false;
            }
#else
            catch (Exception)
            {
            }
#endif

            return true;

            
        }
Ejemplo n.º 9
0
        static void Main(string[] args)
        {
            /*
             * Make sure this path contains the umundoNativeCSharp.dll!
             */
            SetDllDirectory("C:\\Users\\sradomski\\Desktop\\build\\umundo\\lib");
            org.umundo.core.Node node = new org.umundo.core.Node();
            Publisher pub = new Publisher("pingpong");
            PingReceiver recv = new PingReceiver();
            Subscriber sub = new Subscriber("pingpong", recv);
            node.addPublisher(pub);
            node.addSubscriber(sub);

            while (true)
            {
                Message msg = new Message();
                String data = "data";
                System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
                byte[] buffer = enc.GetBytes(data);
                msg.setData(buffer);
                msg.putMeta("foo", "bar");
                Console.Write("o");
                pub.send(msg);
                System.Threading.Thread.Sleep(1000);
            }
        }
Ejemplo n.º 10
0
 public static string Encode(string value)
 {
     var hash = System.Security.Cryptography.SHA1.Create();
     var encoder = new System.Text.ASCIIEncoding();
     var combined = encoder.GetBytes(value ?? "");
     return BitConverter.ToString(hash.ComputeHash(combined)).ToLower().Replace("-", "");
 }
        /// <summary>
        /// Function for getting a token from ACS using Application Service principal Id and Password.
        /// </summary>
        public static AADJWTToken GetAuthorizationToken(string tenantName, string appPrincipalId, string password)
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(String.Format(StringConstants.AzureADSTSURL, tenantName));
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            string postData = "grant_type=client_credentials";            
            postData += "&resource=" + HttpUtility.UrlEncode(StringConstants.GraphPrincipalId);
            postData += "&client_id=" + HttpUtility.UrlEncode(appPrincipalId);
            postData += "&client_secret=" + HttpUtility.UrlEncode(password);
            byte[] data = encoding.GetBytes(postData);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;

            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }
            using (var response = request.GetResponse())
            {
                using (var stream = response.GetResponseStream())
                {
                    DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(AADJWTToken));
                    AADJWTToken token = (AADJWTToken)(ser.ReadObject(stream));
                    return token;
                }
            }
        }
Ejemplo n.º 12
0
 /// <summary>
 /// 截取指定长度字符串,汉字为2个字符
 /// </summary>
 /// <param name="inputString">要截取的目标字符串</param>
 /// <param name="len">截取长度</param>
 /// <returns>截取后的字符串</returns>
 public static string CutString(string inputString, int len)
 {
     System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
     int tempLen = 0;
     string tempString = "";
     byte[] s = ascii.GetBytes(inputString);
     for (int i = 0; i < s.Length; i++)
     {
         if ((int)s[i] == 63)
             tempLen += 2;
         else
             tempLen += 1;
         try
         {
             tempString += inputString.Substring(i, 1);
         }
         catch
         {
             break;
         }
         if (tempLen > len)
             break;
     }
     return tempString;
 }
Ejemplo n.º 13
0
        /// <summary>
        /// Uidチェック(0~9|a~z|A~Z)かつ18桁
        /// </summary>
        /// <param name="uid">UID</param>
        /// <returns></returns>
        private static bool CheckMuid(string uid)
        {
            var asciiEncoding = new System.Text.ASCIIEncoding();

            var rst = uid.Select((t, i) => (int)asciiEncoding.GetBytes(uid.Substring(i, 1))[0]).Aggregate(true, (current, z) => current && ((47 < z && z < 58) || (64 < z && z < 91) || (96 < z && z < 123) || z==46));
            return  rst;
        }
Ejemplo n.º 14
0
 private void WriteData(Stream requestStream, string data)
 {
     System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
     byte[] dataAsBytes = encoding.GetBytes(data);
     Stream dataStream = requestStream;
     dataStream.Write(dataAsBytes, 0, dataAsBytes.Length);
     dataStream.Close();
 }
Ejemplo n.º 15
0
        /// <summary>
        /// Convert string to a byte array.
        /// </summary>
        /// <param name="text">String to convert.</param>
        /// <returns>Byte array. null if text is null, and empty array if
        /// the string is empty.
        ///</returns>
        public static byte[] StringToByteArray(string text)
        {
            if (text == null)
                return null;

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            return encoding.GetBytes(text);
        }
Ejemplo n.º 16
0
        public static string Encode(string value)
        {
            var hash     = System.Security.Cryptography.SHA256.Create();
            var encoder  = new System.Text.ASCIIEncoding();
            var combined = encoder.GetBytes(value ?? "");

            return(BitConverter.ToString(hash.ComputeHash(combined))
                   .ToLower()
                   .Replace("-", ""));
        }
Ejemplo n.º 17
0
 public mbFourcc(string str)
 {
     while (str.Length < 4)
     {
         str += " ";
     }
     System.Text.ASCIIEncoding asc = new System.Text.ASCIIEncoding();
     this.dat = new byte[4];
     asc.GetBytes(str, 0, 4, this.dat, 0);
 }
Ejemplo n.º 18
0
        public void GetStringFromAsciiArrayTest()
        {
            string expected = "Test!";

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            var self   = encoding.GetBytes(expected);
            var actual = self.GetStringFromArray(EncodingType.Ascii);

            Assert.AreEqual(expected, actual);
        }
Ejemplo n.º 19
0
        /**
         * Not used in current implementation. Commented to
         * reduce compilation warnings.
         * 29Dec2014
         * protected byte[] AuthMessage(string approval_code)
         * {
         *  System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
         *  string display_message = "Thank You!";
         *
         *  byte[] msg = new byte[31 + display_message.Length + 2];
         *
         *  msg[0] = 0x2; // STX
         *  msg[1] = 0x35; // Auth Code
         *  msg[2] = 0x30;
         *  msg[3] = 0x2e;
         *
         *  byte[] tmp = enc.GetBytes(terminal_serial_number);
         *  for(int i=0; i<8; i++)
         *      msg[i+4] = tmp[i];
         *
         *  msg[12] = 0x0;
         *
         *  tmp = enc.GetBytes(pos_trans_no);
         *  for(int i=0; i<4; i++)
         *      msg[i+13] = tmp[i];
         *
         *  if(approval_code == "denied"){
         *      msg[17] = 0x45;
         *      msg[18] = 0x3f;
         *  }
         *  else{
         *      msg[17] = 0x41;
         *      msg[18] = 0x3f;
         *  }
         *
         *  tmp = enc.GetBytes(approval_code);
         *  for(int i=0;i<6;i++)
         *      msg[i+19] = tmp[i];
         *
         *  string today = String.Format("(0:yyMMdd)",DateTime.Today);
         *  tmp = enc.GetBytes(today);
         *  for(int i=0;i<4;i++)
         *      msg[i+25] = tmp[i];
         *
         *  tmp = enc.GetBytes(display_message);
         *  for(int i=0;i<tmp.Length;i++)
         *      msg[i+31] = tmp[i];
         *
         *  msg[msg.Length-2] = 0x1c; // ASCII FS delimiter
         *
         *  msg[msg.Length-1] = 0x3; // ETX
         *
         *  return msg;
         * }
         */

        // write DFS configuration values

        /**
         * Not used in current implementation. Commented to
         * reduce compilation warnings.
         * 29Dec2014
         */
        protected byte[] WriteConfigMessage(string group_num, string index_num, string val)
        {
            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            byte[] gb = enc.GetBytes(group_num);
            byte[] ib = enc.GetBytes(index_num);
            byte[] vb = enc.GetBytes(val);

            byte[] msg = new byte[4 + gb.Length + ib.Length + vb.Length + 4];

            msg[0] = 0x2;  // STX
            msg[1] = 0x36; // Write Code
            msg[2] = 0x30;
            msg[3] = 0x2e;

            int pos = 4;

            // write group
            for (int i = 0; i < gb.Length; i++)
            {
                msg[pos++] = gb[i];
            }

            msg[pos++] = 0x1d; // ASII GS delimiter

            // write index
            for (int i = 0; i < ib.Length; i++)
            {
                msg[pos++] = ib[i];
            }

            // write value
            msg[pos++] = 0x1d; // ASII GS delimiter

            for (int i = 0; i < vb.Length; i++)
            {
                msg[pos++] = vb[i];
            }

            msg[msg.Length - 2] = 0x1c; // ASCII FS delimiter

            msg[msg.Length - 1] = 0x3;  // ETX
            return(msg);
        }
        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            string base64s = Convert.ToBase64String(encoding.GetBytes(ann_TextBox.Text));

            resultAndDetails.Results[0].annotation = base64s;
            GmatClubTest.Data.ResultAndDetailsTableAdapters.ResultsTableAdapter ta = new GmatClubTest.Data.ResultAndDetailsTableAdapters.ResultsTableAdapter();
            ta.SqlConnection = connection_;
            ta.Update(resultAndDetails.Results);
        }
Ejemplo n.º 21
0
 /// <summary>
 /// 将字符串转换成ASCIIC码值
 /// </summary>
 /// <param name="character">字符串</param>
 /// <returns></returns>
 private int ASCIIC(string character)
 {
     if (character.Length == 1)
     {
         System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
         int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];
         return(intAsciiCode);
     }
     return(0);
 }
Ejemplo n.º 22
0
        /// <summary>
        /// Convert string to a byte array.
        /// </summary>
        /// <param name="text">String to convert.</param>
        /// <returns>Byte array. null if text is null, and empty array if
        /// the string is empty.
        ///</returns>
        public static byte[] StringToByteArray(string text)
        {
            if (text == null)
            {
                return(null);
            }

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            return(encoding.GetBytes(text));
        }
Ejemplo n.º 23
0
		void Write(string format, params object[] args)
		{
			System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding();

			byte[] WriteBuffer = new byte[1024];
			WriteBuffer = en.GetBytes(string.Format(format, args));

			NetworkStream stream = GetStream();
			stream.Write(WriteBuffer, 0, WriteBuffer.Length);
		}
Ejemplo n.º 24
0
		/// <summary>
		/// Constrói uma chave
		/// </summary>
		/// <param name="usuário">Usuário</param>
		/// <param name="senha">Senha</param>
		public Chave(string usuário, string senha)
		{
			MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
			System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
			byte [] dados;

			dados = ascii.GetBytes(DateTime.Now.Ticks.ToString() + usuário + senha);

			código = md5.ComputeHash(dados);
		}
Ejemplo n.º 25
0
        public static byte[] ASCIIGetBytes(string str)
        {
#if UNITY_IPHONE || UNITY_ANDROID
            System.Text.ASCIIEncoding enconding = new System.Text.ASCIIEncoding();
            return(enconding.GetBytes(str));
#else
            System.Text.UTF8Encoding enconding = new System.Text.UTF8Encoding();
            return(enconding.GetBytes(str));
#endif
        }
Ejemplo n.º 26
0
        private string CreateToken(string message, string secret)
        {
            secret = secret ?? "";
            var encoding = new System.Text.ASCIIEncoding();

            byte[] keyByte      = encoding.GetBytes(secret);
            byte[] messageBytes = encoding.GetBytes(message);
            using (var hmacsha256 = new HMACSHA256(keyByte))
            {
                byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);

                var sb = new System.Text.StringBuilder();
                for (var i = 0; i <= hashmessage.Length - 1; i++)
                {
                    sb.Append(hashmessage[i].ToString("X2"));
                }
                return(sb.ToString());
            }
        }
Ejemplo n.º 27
0
        /// <summary>
        ///		Escribe un mensaje
        /// </summary>
        private void Write(NetworkStream stmNetwork, string strLine)
        {
            System.Text.ASCIIEncoding objEncoder = new System.Text.ASCIIEncoding();
            byte[] arrBytBuffer = objEncoder.GetBytes(strLine + cnstStrLineSeparator);

            // Escribe la cadena codificada
            stmNetwork.Write(arrBytBuffer, 0, arrBytBuffer.Length);
            // Envía la cadena
            stmNetwork.Flush();
        }
Ejemplo n.º 28
0
 public void SendCommandToServer(string Command)
 {
     System.Net.Sockets.NetworkStream ns = this.GetStream();
     byte[] WriteBuffer;
     WriteBuffer = new byte[1024];
     System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding();
     WriteBuffer = en.GetBytes(Command);
     ns.Write(WriteBuffer, 0, WriteBuffer.Length);
     return;
 }
Ejemplo n.º 29
0
 public static int getTagInt(String tag)
 {
     System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
     byte[] chars = enc.GetBytes(tag);
     if (chars.Length != 4)
     {
         throw new Exception("A tag has to be constructed out of 4 characters!");
     }
     return(chars[0] | (chars[1] << 8) | (chars[2] << 16) | (chars[3] << 24));
 }
Ejemplo n.º 30
0
        public string GetCurrentAirInstall(string Location)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            DirectoryInfo             dInfo    = new DirectoryInfo(Location);

            DirectoryInfo[] subdirs = null;
            try
            {
                subdirs = dInfo.GetDirectories();
            }
            catch { return("0.0.0.0"); }
            string latestVersion = "0.0.1";

            foreach (DirectoryInfo info in subdirs)
            {
                latestVersion = info.Name;
            }

            string AirLocation = Path.Combine(Location, latestVersion, "deploy");

            if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "ClientLibCommon.dat")))
            {
                File.Copy(Path.Combine(AirLocation, "lib", "ClientLibCommon.dat"), Path.Combine(Client.ExecutingDirectory, "ClientLibCommon.dat"));
            }
            if (!File.Exists(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite")))
            {
                File.Copy(Path.Combine(AirLocation, "assets", "data", "gameStats", "gameStats_en_US.sqlite"), Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));
            }
            else
            {
                File.Delete(Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));
                File.Copy(Path.Combine(AirLocation, "assets", "data", "gameStats", "gameStats_en_US.sqlite"), Path.Combine(Client.ExecutingDirectory, "gameStats_en_US.sqlite"));
            }

            Copy(Path.Combine(AirLocation, "assets", "images", "abilities"), Path.Combine(Client.ExecutingDirectory, "Assets", "abilities"));
            Copy(Path.Combine(AirLocation, "assets", "images", "champions"), Path.Combine(Client.ExecutingDirectory, "Assets", "champions"));

            var VersionAIR = File.Create(Path.Combine("Assets", "VERSION_AIR"));

            VersionAIR.Write(encoding.GetBytes(latestVersion), 0, encoding.GetBytes(latestVersion).Length);
            VersionAIR.Close();
            return(latestVersion);
        }
Ejemplo n.º 31
0
        protected byte[] PinEntryScreen()
        {
            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
            byte[] pan  = enc.GetBytes(masked_pan);
            byte[] form = enc.GetBytes("pin.K3Z");
            byte[] msg  = new byte[10 + pan.Length + form.Length];

            msg[0] = 0x2;
            msg[1] = 0x33;
            msg[2] = 0x31;
            msg[3] = 0x2e;

            msg[4] = 0x44; // DUKPT, default settings
            msg[5] = 0x2a;

            msg[6] = 0x31;
            msg[7] = 0x1c;

            int pos = 8;

            foreach (byte b in pan)
            {
                msg[pos] = b;
                pos++;
            }

            msg[pos] = 0x1c;
            pos++;


            foreach (byte b in form)
            {
                msg[pos] = b;
                pos++;
            }

            msg[pos] = 0x3;

            System.Console.WriteLine("get pin for:" + masked_pan);

            return(msg);
        }
Ejemplo n.º 32
0
        public override byte[] GetDataBytes()
        {
            byte[] data = new byte[DataLength];
            int    pos  = 0;
            int    temp;

            temp        = pluginName.Length;
            data[pos++] = (byte)temp;
            data[pos++] = (byte)(temp >> 8);
            data[pos++] = (byte)(temp >> 16);
            data[pos++] = (byte)(temp >> 24);

            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

            enc.GetBytes(pluginName).CopyTo(data, pos);
            pos += temp;

            data[pos++] = (byte)pluginVer;
            data[pos++] = (byte)(pluginVer >> 8);
            data[pos++] = (byte)(pluginVer >> 16);
            data[pos++] = (byte)(pluginVer >> 24);

            temp        = username.Length;
            data[pos++] = (byte)temp;
            data[pos++] = (byte)(temp >> 8);
            data[pos++] = (byte)(temp >> 16);
            data[pos++] = (byte)(temp >> 24);

            enc.GetBytes(username).CopyTo(data, pos);
            pos += temp;

            temp        = burntime.Length;
            data[pos++] = (byte)temp;
            data[pos++] = (byte)(temp >> 8);
            data[pos++] = (byte)(temp >> 16);
            data[pos++] = (byte)(temp >> 24);

            enc.GetBytes(burntime).CopyTo(data, pos);
            pos += temp;

            return(data);
        }
        //Response.Write();
        protected void btnExport_Click(object sender, EventArgs e)
        {
            if (hdExport.Value == "ON")
            {
                hdExport.Value = "OFF";
                string strHeaderCols = "CourseID|CourseGrade|GradeLow|CourseCode|CourseName|CourseCount|AlternateCount";
                string strFileName = CP.SetExportFileName("StudentCountByCourses", strSchoolID);

                #region Send Request to ExcelWriter
                string strPostInfo;
                System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                strPostInfo = "SQL=" + strSQL.Replace("+", "~");
                strPostInfo += "&HeaderCols=" + strHeaderCols;
                strPostInfo += "&ReportName=" + lblReportName.Text;
                strPostInfo += "&Description=" + lblDescription.Text;
                strPostInfo += "&SortFilter=" + hdOldSortColumn.Value;
                //Response.Write(strPostInfo);
                //Response.End();
                byte[] buffer1 = encoding.GetBytes(strPostInfo);
                HttpWebRequest NewRequest = (HttpWebRequest)WebRequest.Create("http://172.16.10.19/School/GetXLSUserReport.aspx");
                NewRequest.Method = "POST";
                NewRequest.ContentType = "application/x-www-form-urlencoded";
                NewRequest.ContentLength = buffer1.Length;
                Stream RequestStream = NewRequest.GetRequestStream();
                RequestStream.Write(buffer1, 0, buffer1.Length);

                WebResponse XLSResponse = NewRequest.GetResponse();
                Stream XLSStream2 = XLSResponse.GetResponseStream();

                RequestStream.Close();
                MemoryStream XLSMemoryStram = new MemoryStream();

                // 2048 bytes seemed like a safe amount to read in at a time.
                byte[] buffer2 = new byte[2048];

                int intBytesRead = 0;
                do
                {
                    intBytesRead = XLSStream2.Read(buffer2, 0, buffer2.Length);
                    XLSMemoryStram.Write(buffer2, 0, intBytesRead);
                }
                while (intBytesRead != 0);

                XLSStream2.Close();
                buffer2 = XLSMemoryStram.ToArray();

                Response.Clear();
                Response.ContentType = "application/vnd.ms-excel";
                Response.AddHeader("content-disposition", "attachment;filename=\"" + strFileName + ".xls\"");
                Response.BinaryWrite(buffer2);
                Response.End();
                #endregion
            }
        }
Ejemplo n.º 34
0
        public static MemoryStream StringXmlToStream(string strXml)
        {
            byte[] byteArray = new byte[strXml.Length];
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byteArray = encoding.GetBytes(strXml);
            MemoryStream memoryStream = new MemoryStream(byteArray);

            memoryStream.Seek(0, SeekOrigin.Begin);

            return(memoryStream);
        }
Ejemplo n.º 35
0
        private string HashPassword(string str)
        {
            string rethash = "";

            System.Security.Cryptography.SHA1 hash    = System.Security.Cryptography.SHA1.Create();
            System.Text.ASCIIEncoding         encoder = new System.Text.ASCIIEncoding();
            byte[] combined = encoder.GetBytes(str);
            hash.ComputeHash(combined);
            rethash = Convert.ToBase64String(hash.Hash);
            return(rethash);
        }
Ejemplo n.º 36
0
        internal string CreateSignature(string strSource, string key)
        {
            string Signature = "error";

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte[] keyByte      = encoding.GetBytes(key);
            byte[] messageBytes = encoding.GetBytes(strSource);
            byte[] hashmessage;


            hashmessage = null;
            Signature   = null;
            HMACMD5 hmacmd5 = new HMACMD5(keyByte);

            hashmessage = hmacmd5.ComputeHash(messageBytes);
            Signature   = ByteToString(hashmessage);


            return(Signature);
        }
Ejemplo n.º 37
0
        public static string Encrypty(string text)
        {
            HashAlgorithm hash = new MD5CryptoServiceProvider();

            System.Text.ASCIIEncoding ASCII = new System.Text.ASCIIEncoding();
            Byte[] BytesMessage             = ASCII.GetBytes(text);

            byte[] array = hash.ComputeHash(BytesMessage);

            return(BitConverter.ToString(array));
        }
Ejemplo n.º 38
0
 /// <summary>
 /// MD5加密
 /// </summary>
 /// <param name="str">加密对象</param>
 /// <returns></returns>
 public static string MD5(string str)
 {
     System.Text.ASCIIEncoding ae = new System.Text.ASCIIEncoding();
     System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
     byte[] AfterMD5 = md5.ComputeHash(md5.ComputeHash(ae.GetBytes(str)));
     for (int i = 0; i < AfterMD5.Length; i++)
     {
         AfterMD5[i] = (byte)(AfterMD5[i] % 95 + 32);
     }
     return(ae.GetString(AfterMD5));
 }
Ejemplo n.º 39
0
        public void GetDataSize()
        {
            string identifier = ProceduralDb.TempName();
              var encoding = new System.Text.ASCIIEncoding();

              const string testString = "This is a test";
              var data = encoding.GetBytes(testString);
              ProceduralDb.SetData(identifier, data);

              Assert.AreEqual(data.Length, ProceduralDb.GetDataSize(identifier));
        }
Ejemplo n.º 40
0
        private string CalculateHmac(IUserLoginInfo userLoginInfo)
        {
            var encoding = new System.Text.ASCIIEncoding();
            var bytes    = encoding.GetBytes(userLoginInfo.Date.ToString("u") + userLoginInfo.UserId);

            using (var hmacsha256 = new HMACSHA256(_hmacKey))
            {
                byte[] hashmessage = hmacsha256.ComputeHash(bytes);
                return(Convert.ToBase64String(hashmessage));
            }
        }
Ejemplo n.º 41
0
        string ICedts_PartnerRepository.HashPassword(string str)
        {
            string rethash = string.Empty;

            System.Security.Cryptography.SHA1 hash    = System.Security.Cryptography.SHA1.Create();
            System.Text.ASCIIEncoding         encoder = new System.Text.ASCIIEncoding();
            byte[] combined = encoder.GetBytes(str);
            hash.ComputeHash(combined);
            rethash = Convert.ToBase64String(hash.Hash);
            return(rethash);
        }
Ejemplo n.º 42
0
        /// <summary>
        /// Writes the data (normal vectors and vertices of the triangles) to the chosen file in binary-mode.
        /// </summary>
        /// <param name="filename">Path of the file to be saved.</param>
        public static void WriteToBinary(string filename)
        {
            FileStream fs   = new FileStream(filename, FileMode.Create);
            BinaryWriter bw = new BinaryWriter(fs);

#if !DEBUG
            try {
#endif
            byte abc         = 0;
            byte[] headerArr = new byte[80];
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            encoding.GetBytes(TriMMApp.Lang.GetElementsByTagName("STLHeader")[0].InnerText).CopyTo(headerArr, 0);

            for (int c = 0; c < 80; c++)
            {
                bw.Write(headerArr[c]);
            }

            bw.Write((UInt32)(TriMMApp.Mesh.Count));

            for (int i = 0; i < TriMMApp.Mesh.Count; i++)
            {
                // Normal vector
                for (int j = 0; j < 3; j++)
                {
                    bw.Write((float)TriMMApp.Mesh[i].Normal[j]);
                }

                // Next three are vertices
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        bw.Write((float)TriMMApp.Mesh[i, j][k]);
                    }
                }

                // Last two bytes are only to fill up to 50 bytes
                bw.Write(abc);
                bw.Write(abc);
            }
#if !DEBUG
        }

        catch (Exception exception) {
            MessageBox.Show(exception.Message, TriMMApp.Lang.GetElementsByTagName("ErrorTitle")[0].InnerText, MessageBoxButton.OK, MessageBoxImage.Error);
        } finally {
#endif
            fs.Close();
            bw.Close();
#if !DEBUG
        }
#endif
        }
Ejemplo n.º 43
0
        void Write(string format, params object[] args)
        {
            System.Text.ASCIIEncoding en = new System.Text.ASCIIEncoding();

            byte[] WriteBuffer = new byte[1024];
            WriteBuffer = en.GetBytes(string.Format(format, args));

            NetworkStream stream = GetStream();

            stream.Write(WriteBuffer, 0, WriteBuffer.Length);
        }
Ejemplo n.º 44
0
        public static string GenerateSignature(string apiKey, string apiSecret, string meetingNumber, string ts, string role)
        {
            string message = String.Format("{0}{1}{2}{3}", apiKey, meetingNumber, ts, role);

            apiSecret = apiSecret ?? "";
            var encoding = new System.Text.ASCIIEncoding();

            byte[] keyByte          = encoding.GetBytes(apiSecret);
            byte[] messageBytesTest = encoding.GetBytes(message);
            string msgHashPreHmac   = System.Convert.ToBase64String(messageBytesTest);

            byte[] messageBytes = encoding.GetBytes(msgHashPreHmac);
            using (var hmacsha256 = new HMACSHA256(keyByte))
            {
                byte[] hashmessage = hmacsha256.ComputeHash(messageBytes);
                string msgHash     = System.Convert.ToBase64String(hashmessage);
                string token       = String.Format("{0}.{1}.{2}.{3}.{4}", apiKey, meetingNumber, ts, role, msgHash);
                var    tokenBytes  = System.Text.Encoding.UTF8.GetBytes(token);
                return(System.Convert.ToBase64String(tokenBytes).TrimEnd(padding));
            }
        }
Ejemplo n.º 45
0
        /// <summary>
        /// Builds the signature token to be used in the post request headers
        /// </summary>
        /// <param name="message">The message to be signed</param>
        /// <param name="secret">The signing key</param>
        /// <returns>The signature token to be used in the post request headers</returns>
        private static string BuildSignature(string message, string secret)
        {
            var encoding = new System.Text.ASCIIEncoding();

            byte[] keyByte      = Convert.FromBase64String(secret);
            byte[] messageBytes = encoding.GetBytes(message);
            using (var hmacsha256 = new HMACSHA256(keyByte))
            {
                byte[] hash = hmacsha256.ComputeHash(messageBytes);
                return(Convert.ToBase64String(hash));
            }
        }
Ejemplo n.º 46
0
 public static byte GetASCII(string strChar)
 {
     if (strChar.Length > 0)
     {
         System.Text.ASCIIEncoding objAscii = new System.Text.ASCIIEncoding();
         return((byte)objAscii.GetBytes(strChar)[0]);
     }
     else
     {
         return(0);
     }
 }
Ejemplo n.º 47
0
        private void SendToStatsD(Dictionary <string, string> sampledData, AsyncCallback callback)
        {
            var prefix   = Config.Prefix;
            var encoding = new System.Text.ASCIIEncoding();

            foreach (var stat in sampledData.Keys)
            {
                var stringToSend = string.Format("{0}{1}:{2}", prefix, stat, sampledData[stat]);
                var sendData     = encoding.GetBytes(stringToSend);
                _client.BeginSend(sendData, sendData.Length, callback, null);
            }
        }
Ejemplo n.º 48
0
        static public Byte[][] strArrayToByteArrayArray(string[] str)
        {
            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            int size = str.Length;

            byte[][] result = new byte[size][];
            for (int i = 0; i < size; ++i)
            {
                result[i] = encoding.GetBytes(str[i]);
            }
            return(result);
        }
        private TokenPassportSignature ComputeSignature(string compId, string consumerKey, string consumerSecret,
                                                        string tokenId, string tokenSecret, string nonce, long timestamp)
        {
            string baseString = compId + "&" + consumerKey + "&" + tokenId + "&" + nonce + "&" + timestamp;
            string key        = consumerSecret + "&" + tokenSecret;
            string signature  = "";
            var    encoding   = new System.Text.ASCIIEncoding();

            byte[] keyBytes        = encoding.GetBytes(key);
            byte[] baseStringBytes = encoding.GetBytes(baseString);
            using (var hmacSha1 = new HMACSHA256(keyBytes))
            {
                byte[] hashBaseString = hmacSha1.ComputeHash(baseStringBytes);
                signature = Convert.ToBase64String(hashBaseString);
            }
            TokenPassportSignature sign = new TokenPassportSignature();

            sign.algorithm = "HMAC-SHA256";
            sign.Value     = signature;
            return(sign);
        }
Ejemplo n.º 50
0
		private static void WriteLog(string text)
		{
			if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["isLogged"]) && WebConfigurationManager.AppSettings["isLogged"] == "true")
			{
				string file = HttpContext.Current.Server.MapPath("~/email.log");
				FileStream f = new FileStream(file, FileMode.Append);
				string testText = text;
				System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
				byte[] bytes = encoding.GetBytes(testText);
				f.Write(bytes, 0, bytes.Length);
				f.Close();
			}
		}
Ejemplo n.º 51
0
 /// <summary>
 /// 测试git
 /// </summary>
 /// <param name="character"></param>
 /// <returns></returns>
 public static int Asc(string character)
 {
     if (character.Length == 1)
     {
         System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
         int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];
         return (intAsciiCode);
     }
     else
     {
         throw new Exception("Character is not valid.");
     }
 }
Ejemplo n.º 52
0
        public static int AddCommand(byte cmd, string buff)
        {
            if(buff.Length >= 16){
                throw new Exception("text too long! :(");
            }

            System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();

            cmdlist.Enqueue(new Command{cmd = cmd,
                                    len = Convert.ToByte(buff.Length),
                                    buf = enc.GetBytes(buff)});
            return cmdlist.Count;
        }
Ejemplo n.º 53
0
        private void AcceptCallback(IAsyncResult ar)
        {
            // Get the socket that handles the client request.
            Socket sock = (Socket)ar.AsyncState;
            Socket client = sock.EndAccept (ar);

            Console.Error.WriteLine ("Got connection from {0}", client.RemoteEndPoint);

              		System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding ();
            client.Send (encoding.GetBytes ("Hello world!\n"));
            client.Close ();
              		allDone.Set ();
        }
Ejemplo n.º 54
0
        /// <summary>
        /// Base64s the encode.
        /// </summary>
        /// <returns>The encode.</returns>
        /// <param name="http_user">Http_user.</param>
        /// <param name="http_pw">Http_pw.</param>
        public string base64Encode(string http_user, string http_pw)
        {
            //zum testen
            //http_user = "******";
            //http_pw = "scdsoft1";

            string user_pw = http_user + ":" + http_pw;

            System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
            byte[] bytes = encoding.GetBytes(user_pw);
            string base64 = System.Convert.ToBase64String(bytes);

            return "Basic " + base64;
        }
Ejemplo n.º 55
0
 public static bool IsNumeric(string str)
 {
     if (str == null || str.Length == 0)
         return false;
     System.Text.ASCIIEncoding ascii = new System.Text.ASCIIEncoding();
     byte[] bytestr = ascii.GetBytes(str);
     foreach (byte c in bytestr)
     {
         if (c < 48 || c > 57)
         {
             return false;
         }
     }
     return true;
 }
 public static PropertyItem GetPropertyItem(int id, string value)
 {
     if (propertyItem == null)
     {
         System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(PropertyItemProvider));
         Bitmap bmp = (Bitmap)resources.GetObject("propertyitemcontainer");
         propertyItem = bmp.GetPropertyItem(bmp.PropertyIdList[0]);
         propertyItem.Type = 2; // string
     }
     propertyItem.Id = id;
     System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
     propertyItem.Value = encoding.GetBytes(value + " ");
     propertyItem.Len = value.Length + 1;
     return propertyItem;
 }
Ejemplo n.º 57
0
        public static long get(string name, int binKeyL)
        {
            SHA1 sha = SHA1.Create();
            System.Text.ASCIIEncoding encoder = new System.Text.ASCIIEncoding();
            byte[] combined = encoder.GetBytes(name);
            sha.ComputeHash(combined);
            string urlHash = Convert.ToBase64String(sha.Hash);

            byte[] urlArray = Convert.FromBase64String(urlHash);
            long ret = BitConverter.ToInt64(urlArray, 0);

            ret = ret % (2 ^ binKeyL);
            if (ret < 0) { ret = -ret; }
            return ret;
        }
        public static void ReceiveCallback(IAsyncResult AsyncCall)
        {
            var encoding = new System.Text.ASCIIEncoding();
            var message = encoding.GetBytes("I am a little busy, come back later!");

            var listener = (Socket)AsyncCall.AsyncState;
            var client = listener.EndAccept(AsyncCall);

            Console.WriteLine("Received Connection from {0}", client.RemoteEndPoint);
            client.Send(message);

            Console.WriteLine("Ending the connection");
            client.Close();

            listener.BeginAccept(new AsyncCallback(ReceiveCallback), listener);
        }
Ejemplo n.º 59
0
 private string CalculateShaPassHash(string name, string password)
 {
     string encoded = "";
     try
     {
         System.Security.Cryptography.SHA1 hash = System.Security.Cryptography.SHA1.Create();
         var encoder = new System.Text.ASCIIEncoding();
         byte[] combined = encoder.GetBytes(name.ToUpper() + ":" + password.ToUpper());
         hash.ComputeHash(combined);
         encoded = Convert.ToBase64String(hash.Hash);
     }
     catch (Exception ex)
     {
         string strerr = "Error in HashCode : " + ex.Message;
     }
     return encoded;
 }
Ejemplo n.º 60
0
        public static string ConvertToSHA1(string text)
        {
            try
            {
                var encoder = new System.Text.ASCIIEncoding();
                byte[] buffer = encoder.GetBytes(text);
                var cryptoTransformSHA1 = new SHA1CryptoServiceProvider();
                string hash = BitConverter.ToString(
                    cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");

                return hash.ToLower();
            }
            catch (Exception)
            {
                return string.Empty;
            }
        }