static public int GetDecoder(IntPtr l) { try { System.Text.UnicodeEncoding self = (System.Text.UnicodeEncoding)checkSelf(l); var ret = self.GetDecoder(); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
public String Md5Encryption(String src) { System.Text.UnicodeEncoding encode = new System.Text.UnicodeEncoding(); System.Text.Decoder decode = encode.GetDecoder(); MD5 md5 = new MD5CryptoServiceProvider(); byte[] password = new byte[encode.GetByteCount(src)]; char[] char_password = new char[encode.GetCharCount(password)]; password = encode.GetBytes(src); password = md5.ComputeHash(password); int length = encode.GetByteCount(src); if (length > 16) { length = 16; } decode.GetChars(password, 0, length, char_password, 0); return(new String(char_password)); }
public void PosTest1() { Char[] srcChars = GetCharArray(10); Char[] desChars = new Char[10]; Byte[] bytes = new Byte[20]; int buffer; int outChars; bool completed; UnicodeEncoding uEncoding = new UnicodeEncoding(); int byteCount = uEncoding.GetBytes(srcChars, 0, 10, bytes, 0); bool expectedValue = true; bool actualValue = true; Decoder dC = uEncoding.GetDecoder(); dC.Convert(bytes, 0, 20, desChars, 0, 10, true, out buffer, out outChars, out completed); if (completed) { for (int i = 0; i < 10; i++) { actualValue = actualValue & (desChars[i] == srcChars[i]); } } Assert.Equal(expectedValue, actualValue); }
private void UsingMemoryStream() { System.Threading.Thread.Sleep(5000); Console.WriteLine("Memory Stream Example"); int count; byte[] byteArray; char[] charArray; UnicodeEncoding uniEncoding = new UnicodeEncoding(); byte[] firstString = uniEncoding.GetBytes("Invalid file path character are: "); byte[] secondString = uniEncoding.GetBytes(Path.GetInvalidFileNameChars()); using (MemoryStream memStream = new MemoryStream(100)) { memStream.Write(firstString, 0, firstString.Length); count = 0; while(count < secondString.Length) { memStream.WriteByte(secondString[count++]); } Console.WriteLine("Capacity = {0}, Length = {1}, Position = {2}", memStream.Capacity, memStream.Length, memStream.Position); memStream.Seek(0, SeekOrigin.Begin); byteArray = new byte[memStream.Length]; count = memStream.Read(byteArray, 0, 20); while(count<memStream.Length) { byteArray[count++] = Convert.ToByte(memStream.ReadByte()); } charArray = new char[uniEncoding.GetCharCount(byteArray,0,count)]; uniEncoding.GetDecoder().GetChars(byteArray, 0, count, charArray, 0); Console.WriteLine(charArray); } }