//Metodo para el hash de la password private string Hash(string password) { var bytes = new System.Text.UTF32Encoding().GetBytes(password); byte[] hashBytes = new System.Security.Cryptography.SHA512Managed().ComputeHash(bytes); return(Convert.ToBase64String(hashBytes)); }
public void Read_Timeout() { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { char[] charXmitBuffer = TCSupport.GetRandomChars(512, TCSupport.CharacterOptions.None); byte[] byteXmitBuffer = new System.Text.UTF32Encoding().GetBytes(charXmitBuffer); char[] charRcvBuffer = new char[charXmitBuffer.Length]; int result; Debug.WriteLine( "Verifying that Read(char[], int, int) works appropriately after TimeoutException has been thrown"); com1.Encoding = new System.Text.UTF32Encoding(); com2.Encoding = new System.Text.UTF32Encoding(); com1.ReadTimeout = 500; // 20 seconds com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } //Write the first 3 bytes of a character com2.Write(byteXmitBuffer, 0, 3); try { com1.Read(charXmitBuffer, 0, charXmitBuffer.Length); Fail("Err_29299aize Expected ReadTo to throw TimeoutException"); } catch (TimeoutException) { } //Expected Assert.Equal(3, com1.BytesToRead); com2.Write(byteXmitBuffer, 3, byteXmitBuffer.Length - 3); // retValue &= TCSupport.WaitForPredicate(delegate() {return com1.BytesToRead == byteXmitBuffer.Length; }, // 5000, "Err_91818aheid Expected BytesToRead={0} actual={1}", byteXmitBuffer.Length, com1.BytesToRead); TCSupport.WaitForExpected(() => com1.BytesToRead, byteXmitBuffer.Length, 5000, "Err_91818aheid BytesToRead"); result = com1.Read(charRcvBuffer, 0, charRcvBuffer.Length); Assert.Equal(charXmitBuffer.Length, result); Assert.Equal(charXmitBuffer, charRcvBuffer); VerifyBytesReadOnCom1FromCom2(com1, com2, byteXmitBuffer, charXmitBuffer, charRcvBuffer, 0, charRcvBuffer.Length); } }
static void Main() { var input = Console.ReadLine(); var encoding = new System.Text.UTF32Encoding(); var bytes = encoding.GetBytes(input); // index = start index to read from, // increment with the size of an int when reading int for (int index = 0; index < bytes.Length; index += sizeof(int)) { var unicode = BitConverter.ToInt32(bytes, index); Console.Write(@"\u{0:X4}", unicode); } }
public void Read_Timeout() { using (SerialPort com1 = TCSupport.InitFirstSerialPort()) using (SerialPort com2 = TCSupport.InitSecondSerialPort(com1)) { char[] charXmitBuffer = TCSupport.GetRandomChars(512, TCSupport.CharacterOptions.None); byte[] byteXmitBuffer = new System.Text.UTF32Encoding().GetBytes(charXmitBuffer); char[] charRcvBuffer = new char[charXmitBuffer.Length]; int result; Debug.WriteLine( "Verifying that Read(char[], int, int) works appropriately after TimeoutException has been thrown"); com1.Encoding = new System.Text.UTF32Encoding(); com2.Encoding = new System.Text.UTF32Encoding(); com1.ReadTimeout = 500; // 20 seconds com1.Open(); if (!com2.IsOpen) //This is necessary since com1 and com2 might be the same port if we are using a loopback { com2.Open(); } //Write the first 3 bytes of a character com2.Write(byteXmitBuffer, 0, 3); Assert.Throws <TimeoutException>(() => com1.ReadChar()); Assert.Equal(3, com1.BytesToRead); com2.Write(byteXmitBuffer, 3, byteXmitBuffer.Length - 3); TCSupport.WaitForExpected(() => com1.BytesToRead, byteXmitBuffer.Length, 5000, "Err_91818aheid BytesToRead"); result = com1.ReadChar(); if (result != charXmitBuffer[0]) { Fail("Err_0158ahei Expected ReadChar to read {0}({0:X}) actual {1}({1:X})", charXmitBuffer[0], result); } else { charRcvBuffer[0] = (char)result; int readResult = com1.Read(charRcvBuffer, 1, charRcvBuffer.Length - 1); if (readResult + 1 != charXmitBuffer.Length) { Fail("Err_051884ajoedo Expected Read to read {0} characters actually read {1}", charXmitBuffer.Length - 1, readResult); } else { for (int i = 0; i < charXmitBuffer.Length; ++i) { if (charRcvBuffer[i] != charXmitBuffer[i]) { Fail("Err_05188ahed Characters differ at {0} expected:{1}({1:X}) actual:{2}({2:X})", i, charXmitBuffer[i], charRcvBuffer[i]); } } } } VerifyBytesReadOnCom1FromCom2(com1, com2, byteXmitBuffer, charXmitBuffer); } }