当前位置: 首页>>代码示例>>C#>>正文


C# UnicodeEncoding.GetString方法代码示例

本文整理汇总了C#中System.Text.UnicodeEncoding.GetString方法的典型用法代码示例。如果您正苦于以下问题:C# UnicodeEncoding.GetString方法的具体用法?C# UnicodeEncoding.GetString怎么用?C# UnicodeEncoding.GetString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Text.UnicodeEncoding的用法示例。


在下文中一共展示了UnicodeEncoding.GetString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

        static void Main(string[] args)
        {
            RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
            string publicKeyXML = rsa.ToXmlString(false);
            string privateKeyXML = rsa.ToXmlString(true);

            UnicodeEncoding ByteConverter = new UnicodeEncoding();
            byte[] dataToEncrypt = ByteConverter.GetBytes("My secret data!");
            Console.WriteLine("Encrypting: {0}", ByteConverter.GetString(dataToEncrypt));

            byte[] encryptedData;
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {
                RSA.FromXmlString(publicKeyXML);
                encryptedData = RSA.Encrypt(dataToEncrypt, false);
            }

            Console.WriteLine("Encrypted data: {0}", ByteConverter.GetString(encryptedData));

            byte[] decryptedData;
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {
                RSA.FromXmlString(privateKeyXML);
                decryptedData = RSA.Decrypt(encryptedData, false);
            }

            string decryptedString = ByteConverter.GetString(decryptedData);
            Console.WriteLine("Decrypted data: {0}", decryptedString);

            Console.WriteLine("Press a key to exit");
            Console.ReadKey();
        }
开发者ID:jbijoux,项目名称:Exam70_483,代码行数:32,代码来源:Program.cs

示例2: RSAEncrypt

        static void RSAEncrypt()
        {
            UnicodeEncoding bytConvertor = new UnicodeEncoding();
            byte[] plainData = bytConvertor.GetBytes("Sample data");
            RSACryptoServiceProvider RSAServiceProvider = new RSACryptoServiceProvider();

            byte[] enData = Encrypt(plainData, RSAServiceProvider.ExportParameters(false));
            Console.WriteLine("Encrypted Output: {0}", bytConvertor.GetString(enData));

            byte[] deData = Decrypt(enData, RSAServiceProvider.ExportParameters(true));
            Console.WriteLine("Decrypted Output: {0}", bytConvertor.GetString(deData));
        }
开发者ID:cleancodenz,项目名称:MVC4DEV,代码行数:12,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            try
            {
                UnicodeEncoding ByteConverter = new UnicodeEncoding();

                byte[] dataToEncrypt = ByteConverter.GetBytes("bbbbbbbb");
                byte[] encryptedData;
                byte[] decryptedData;
                char result;
                using(RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
                {
                    encryptedData = RSAEncrypt(dataToEncrypt, RSA.ExportParameters(false), false);
                    foreach (byte number in encryptedData)
                    {
                        result = Convert.ToChar(number);
                        Console.WriteLine($"number: {number} convert: {result}");
                    }
                    Console.WriteLine($"tam> {encryptedData.Length}");
                    decryptedData = RSADecrypt(encryptedData, RSA.ExportParameters(true), false);

                    Console.WriteLine($"1 - {ByteConverter.GetString(decryptedData)}");
                }
            }
            catch (ArgumentNullException)
            {
                Console.WriteLine("Encryption failed");
            }

            Console.ReadKey();
        }
开发者ID:Patiqundead,项目名称:Seguranca,代码行数:31,代码来源:Program.cs

示例4: EncryptSomeText

        public static void EncryptSomeText()
        {
            //Init keys
            GeneratePublicAndPrivateKeys();

            UnicodeEncoding ByteConverter = new UnicodeEncoding();
            byte[] dataToEncrypt = ByteConverter.GetBytes("My ultra secret message!");

            byte[] encryptedData;
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {
                RSA.FromXmlString(publicKeyXML);
                encryptedData = RSA.Encrypt(dataToEncrypt, false);
            }

            byte[] decryptedData;
            using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
            {
                RSA.FromXmlString(privateKeyXML);
                decryptedData = RSA.Decrypt(encryptedData, false);
            }

            string decryptedString = ByteConverter.GetString(decryptedData);
            Console.WriteLine(decryptedString);
        }
开发者ID:Chaek,项目名称:MCSD,代码行数:25,代码来源:RSAEncryption.cs

示例5: Decrypt

        public string Decrypt(string base64code)
        {
            try
            {
                //Create a UnicodeEncoder to convert between byte array and string.
                UnicodeEncoding ByteConverter = new UnicodeEncoding();

                //Create a new instance of RSACryptoServiceProvider to generate
                //public and private key data.
                RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
                RSA.FromXmlString(privateKey);

                byte[] encryptedData;
                byte[] decryptedData;
                encryptedData = Convert.FromBase64String(base64code);

                //Pass the data to DECRYPT, the private key information
                //(using RSACryptoServiceProvider.ExportParameters(true),
                //and a boolean flag specifying no OAEP padding.
                decryptedData = RSADecrypt(encryptedData, RSA.ExportParameters(true), false);

                //Display the decrypted plaintext to the console.
                return ByteConverter.GetString(decryptedData);
            }
            catch (Exception exc)
            {
                //Exceptions.LogException(exc);
                Console.WriteLine(exc.Message);
                return "";
            }
        }
开发者ID:cpm2710,项目名称:cellbank,代码行数:31,代码来源:RSAUtil.cs

示例6: GenerateSaltValue

        //generates a random salt value based on the timestamp
        public static string GenerateSaltValue()
        {
            UnicodeEncoding utf16 = new UnicodeEncoding();

            if (utf16 != null)
            {
                // Create a random number object

                Random random = new Random(unchecked((int)DateTime.Now.Ticks));

                if (random != null)
                {
                    // create random values in an array

                    byte[] saltValue = new byte[16];

                    random.NextBytes(saltValue);

                    // Convert the salt value to a string

                    string saltValueString = utf16.GetString(saltValue);

                    // Return the salt value as a string

                    return saltValueString;
                }
            }

            return null;
        }
开发者ID:BennyFischer,项目名称:nomofv2,代码行数:31,代码来源:Hasher.cs

示例7: Decrypt

        /// <summary>
        /// Triple DES Descrypt
        /// </summary>
        /// <param name="input">String to decrypt</param>
        /// <param name="key">Encryption Key</param>
        /// <returns></returns>
        public static string Decrypt(string input, string key)
        {
            TripleDESCryptoServiceProvider crp =new TripleDESCryptoServiceProvider();
            System.Text.UnicodeEncoding uEncode = new UnicodeEncoding();
            System.Text.ASCIIEncoding aEncode =new ASCIIEncoding();

            Byte[] bytCipherText = System.Convert.FromBase64String(input);
            MemoryStream stmPlainText =new MemoryStream();
            MemoryStream stmCipherText = new MemoryStream(bytCipherText);

            Byte[] slt= {0x12};

            PasswordDeriveBytes pdb = new PasswordDeriveBytes(key, slt);
            Byte[] bytDerivedKey = pdb.GetBytes(24);
            crp.Key = bytDerivedKey;

            crp.IV = pdb.GetBytes(8);
            CryptoStream csDecrypted = new CryptoStream(stmCipherText, crp.CreateDecryptor(), CryptoStreamMode.Read);

            StreamWriter sw = new StreamWriter(stmPlainText);
            StreamReader sr = new StreamReader(csDecrypted);
            sw.Write(sr.ReadToEnd());

            sw.Flush();

            crp.Clear();

            return uEncode.GetString(stmPlainText.ToArray());
        }
开发者ID:asr340,项目名称:owasp-code-central,代码行数:35,代码来源:encryption.cs

示例8: ConvertDataSetToXMLFile

        private static void ConvertDataSetToXMLFile(DataSet xmlDS, string xmlFile)
        {
            MemoryStream stream = null;
            XmlTextWriter writer = null;
            try
            {
                stream = new MemoryStream();
                //从stream装载到XmlTextReader
                writer = new XmlTextWriter(stream, Encoding.Unicode);

                //用WriteXml方法写入文件.
                xmlDS.WriteXml(writer);
                int count = (int)stream.Length;
                byte[] arr = new byte[count];
                stream.Seek(0, SeekOrigin.Begin);
                stream.Read(arr, 0, count);

                //返回Unicode编码的文本
                UnicodeEncoding utf = new UnicodeEncoding();
                StreamWriter sw = new StreamWriter(xmlFile);
                sw.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                sw.WriteLine(utf.GetString(arr).Trim());
                sw.Close();
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (writer != null)
                    writer.Close();
            }
        }
开发者ID:IoRyY,项目名称:XYSTest,代码行数:34,代码来源:Form1.cs

示例9: Encrypt

        public override void Encrypt()
            {
                //RSA Rsa = new RSA();
                //base.Component.Text = Rsa.encode(base.Component.tp.Text);

                try
                {
                    UnicodeEncoding ByteConverter = new UnicodeEncoding();
                    byte[] encryptedData;
                    using (RSACryptoServiceProvider RSA = new RSACryptoServiceProvider())
                    {
                        RSA.ImportParameters(RSA.ExportParameters(false));
  
                        
                        byte[] Data = ByteConverter.GetBytes(base.Component.tp.Text.ToString());
                        encryptedData = RSA.Encrypt(Data , false);
                    }
                    base.Component.Text = ByteConverter.GetString(encryptedData);
                }
                //Catch and display a CryptographicException  
                //to the console.
                catch (CryptographicException e)
                {
                    Console.WriteLine(e.Message);
                    base.Component.Text = base.Component.tp.Text.ToString();
                }
               
            }
开发者ID:mrVengr,项目名称:EveryDayNote,代码行数:28,代码来源:TextEncrypt.cs

示例10: ConvertDataSetToXML

 //将DataSet转换为xml对象字符串
 public static string ConvertDataSetToXML(DataSet xmlDS)
 {
     MemoryStream stream = null;
     XmlTextWriter writer = null;
     try
     {
         stream = new MemoryStream();
         //从stream装载到XmlTextReader
         writer = new XmlTextWriter(stream, Encoding.Unicode);
         //用WriteXml方法写入文件.
         xmlDS.WriteXml(writer);
         int count = (int)stream.Length;
         byte[] arr = new byte[count];
         stream.Seek(0, SeekOrigin.Begin);
         stream.Read(arr, 0, count);
         UnicodeEncoding utf = new UnicodeEncoding();
         return utf.GetString(arr).Trim();
     }
     catch (System.Exception ex)
     {
         throw ex;
     }
     finally
     {
         if (writer != null) writer.Close();
     }
 }
开发者ID:icegithub,项目名称:csharp-exercise,代码行数:28,代码来源:XmlDatasetConvert.cs

示例11: AsSha512

 public static string AsSha512(string text)
 {
     var encode = new UnicodeEncoding();
     var bytPassword = encode.GetBytes(text);
     var hash = new SHA512Managed().ComputeHash(bytPassword);
     return encode.GetString(hash);
 }
开发者ID:adrianoviana87,项目名称:Ppm,代码行数:7,代码来源:Encript.cs

示例12: Run

        public void Run()
        {
            var _exportKey = new RSACryptoServiceProvider();
            string publicKeyXML = _exportKey.ToXmlString(false);
            string privateKeyXML = _exportKey.ToXmlString(true);

            var ByteConverter = new UnicodeEncoding();
            byte[] dataToEncrypt = ByteConverter.GetBytes("My Secret Data!");

            byte[] encryptedData;
            using (var RSA = new RSACryptoServiceProvider())
            {
                RSA.FromXmlString(publicKeyXML);
                encryptedData = RSA.Encrypt(dataToEncrypt, false);
            }

            byte[] decryptedData;
            using (var RSA = new RSACryptoServiceProvider())
            {
                RSA.FromXmlString(privateKeyXML);
                decryptedData = RSA.Decrypt(encryptedData, false);
            }

            string decryptedString = ByteConverter.GetString(decryptedData);
            Console.WriteLine(decryptedString); // Displays: My Secret Data!        }
        }
开发者ID:rrsc,项目名称:ProgrammingInCSharp,代码行数:26,代码来源:UsingAPublicAndPrivateKeyToEncryptAndDecryptData.cs

示例13: CheckOnRegister

        public bool CheckOnRegister(string email)
        {
            IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
            IPEndPoint remoteEndPoint = new IPEndPoint(ipAddress, 8145);
            UnicodeEncoding encoding = new UnicodeEncoding();
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Connect(remoteEndPoint);

            //encode from a string format to bytes ("our packages")
            Byte[] bufferOut = encoding.GetBytes(email);

            socket.Send(bufferOut);

            byte[] bytes = new byte[1024];
            int bytesRecieved = socket.Receive(bytes);

            string mess = encoding.GetString(bytes, 0, bytesRecieved);
            if (mess == "1")
            {
                return true;
            }
            else
            {
                return false;

            }
        }
开发者ID:Israa92,项目名称:Doctor,代码行数:27,代码来源:Client.cs

示例14: HashAndSignString

        /// <summary>
        /// Hash the data and generate signature
        /// </summary>
        /// <param name="dataToSign"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public static string HashAndSignString(string dataToSign, RSAParameters key)
        {
            UnicodeEncoding ByteConverter = new UnicodeEncoding();
            byte[] signatureBytes = HashAndSignBytes(ByteConverter.GetBytes(dataToSign), key);

            return ByteConverter.GetString(signatureBytes);
        }
开发者ID:akhleshg,项目名称:datastore-service,代码行数:13,代码来源:CryptographyHelper.cs

示例15: GenerateSaltValue

        private static string GenerateSaltValue()
        {
            UnicodeEncoding utf16 = new UnicodeEncoding();

            if (utf16 != null)
            {
                // Create a random number object seeded from the value
                // of the last random seed value. This is done
                // interlocked because it is a static value and we want
                // it to roll forward safely.

                Random random = new Random(unchecked((int)DateTime.Now.Ticks));

                if (random != null)
                {
                    // Create an array of random values.

                    byte[] saltValue = new byte[SaltValueSize];

                    random.NextBytes(saltValue);

                    // Convert the salt value to a string. Note that the resulting string
                    // will still be an array of binary values and not a printable string.
                    // Also it does not convert each byte to a double byte.

                    string saltValueString = utf16.GetString(saltValue);

                    // Return the salt value as a string.

                    return saltValueString;
                }
            }

            return null;
        }
开发者ID:icarus5,项目名称:Solaris,代码行数:35,代码来源:UnitTest1.cs


注:本文中的System.Text.UnicodeEncoding.GetString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。