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


C# UnicodeEncoding.GetBytes方法代码示例

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


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

示例1: password_crypt

        string password_crypt(string password, string setting)
        {
            string _setting = setting.Substring(0, 12);
            if (_setting[0] != '$' || _setting[2] != '$')
                return null;

            int count_log2 = password_get_count_log2(setting);
            string salt = _setting.Substring(4, 8);
            if (salt.Length < 8)
                return null;
            int count = 1 << count_log2;
            SHA512 shaM = new SHA512Managed();
            Encoding unicode = new UnicodeEncoding(true, false);
            byte[] data = unicode.GetBytes(salt + password);
            byte[] pass = unicode.GetBytes(password);
            byte[] hash = shaM.ComputeHash(data);
            for (int c = 0; c < count; c++)
            {
                data = new byte[hash.Length + pass.Length];
                hash.CopyTo(data, 0);
                pass.CopyTo(data, hash.Length);
                hash = shaM.ComputeHash(data);
            }
            string output = setting + custom64(hash);
            return output.Substring(0, hash_length);
        }
开发者ID:Inexika,项目名称:drupal_hash_cs,代码行数:26,代码来源:Program.cs

示例2: DecryptStringWith3DES

        public static string DecryptStringWith3DES(string data, string key, string iv)
        {
            UnicodeEncoding unicode = new UnicodeEncoding();
            Byte[] Bytes = Convert.FromBase64String(data);

            MemoryStream mem = new MemoryStream(100);
            TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();

            Byte[] KeyBytes = unicode.GetBytes(key);
            Byte[] tmpBytes = new Byte[16];
            Array.Copy(KeyBytes, tmpBytes, KeyBytes.Length < 16 ? KeyBytes.Length : 16);
            KeyBytes = tmpBytes;

            if(tdes.ValidKeySize(KeyBytes.Length*8))
                System.Diagnostics.Debug.WriteLine("Key size valid");
            if(TripleDESCryptoServiceProvider.IsWeakKey(KeyBytes))
                System.Diagnostics.Debug.WriteLine("Key weak");
            CryptoStream CrStream = new CryptoStream(mem, tdes.CreateDecryptor(KeyBytes, unicode.GetBytes(iv)), CryptoStreamMode.Write);

            for(int i = 0; i < Bytes.Length; i++)
                CrStream.WriteByte(Bytes[i]);

            CrStream.FlushFinalBlock();

            string result = unicode.GetString(mem.GetBuffer(), 0, (int)mem.Length);
            CrStream.Dispose();
            return result;
        }
开发者ID:cyotek,项目名称:translateclient,代码行数:28,代码来源:CryptoTools.cs

示例3: hashPassword

        public static string hashPassword(string password, string salt)
        {
            System.Text.UnicodeEncoding ue = new UnicodeEncoding();
            byte[] uePassword = ue.GetBytes(password);
            byte[] retVal = null;

            HMACSHA1 SHA1KeyedHasher = new HMACSHA1();
            SHA1KeyedHasher.Key = ue.GetBytes(salt);
            retVal = SHA1KeyedHasher.ComputeHash(uePassword);

            return Convert.ToBase64String(retVal);
        }
开发者ID:yoorke,项目名称:pinshop,代码行数:12,代码来源:UserBL.cs

示例4: 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

示例5: DecryptFile

		public static void DecryptFile(string inputFile, string outputFile, string password)
		{
			{
				var unicodeEncoding = new UnicodeEncoding();
				byte[] key = unicodeEncoding.GetBytes(FormatPassword(password));

				if (!File.Exists(inputFile))
				{
					File.Create(inputFile);
				}
				FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);
				var rijndaelManaged = new RijndaelManaged();
				var cryptoStream = new CryptoStream(fsCrypt, rijndaelManaged.CreateDecryptor(key, key), CryptoStreamMode.Read);
				var fileStream = new FileStream(outputFile, FileMode.Create);

				try
				{
					int data;
					while ((data = cryptoStream.ReadByte()) != -1)
						fileStream.WriteByte((byte)data);
				}
				catch { throw; }
				finally
				{
					fsCrypt.Close();
					fileStream.Close();
					cryptoStream.Close();
				}
			}
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:30,代码来源:EncryptHelper.cs

示例6: 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

示例7: Main

        static void Main(string[] args)
        {
            /*
                MD5: MD5CryptoServiceProvider
                RIPEMD-160: RIPEMD160Managed
                SHA: SHA1CryptoServiceProvider e SHA1Managed
                Keyed hash: HMAC e MACTripleDES
            */

            //geração de hash com SHA1
            StreamReader sr = new StreamReader("Arquivo.txt");

            String mensagem = sr.ReadToEnd();

            sr.Close();

            SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();

            UnicodeEncoding ue = new UnicodeEncoding();

            byte[] bytes = ue.GetBytes(mensagem);

            byte[] hash = sha1.ComputeHash(bytes);

            Gravar(hash, sha1.GetType().Name);

            Process.Start("notepad", String.Format("{0}.hash", sha1.GetType().Name));
        }
开发者ID:50minutos,项目名称:VS2010,代码行数:28,代码来源:Program.cs

示例8: 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

示例9: StringToByteArray

 private static byte[] StringToByteArray(string str)
 {
     if (null == str)
         return null;
     System.Text.UnicodeEncoding enc = new System.Text.UnicodeEncoding();
     return enc.GetBytes(str);
 }
开发者ID:netintellect,项目名称:NetOffice,代码行数:7,代码来源:ChangeBinaryDialog.cs

示例10: EncryptFile

        public static void EncryptFile(string inputFile, string outputFile, string password)
        {
            try
            {
                //string password = @"myKey123"; // Your Key Here
                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                string cryptFile = outputFile;
                FileStream fsCrypt = new FileStream(cryptFile, FileMode.Create);

                RijndaelManaged RMCrypto = new RijndaelManaged();

                CryptoStream cs = new CryptoStream(fsCrypt,
                                                   RMCrypto.CreateEncryptor(key, key),
                                                   CryptoStreamMode.Write);

                FileStream fsIn = new FileStream(inputFile, FileMode.Open);

                int data;
                while ((data = fsIn.ReadByte()) != -1)
                    cs.WriteByte((byte) data);

                fsIn.Close();
                cs.Close();
                fsCrypt.Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Encryption failed! {0}", ex);
            }
        }
开发者ID:hkuntal,项目名称:TeamWorkManagement,代码行数:32,代码来源:Program.cs

示例11: 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

示例12: EncryptFile

        internal static void EncryptFile(string inputFile, string outputFile, string password)
        {

            try {
                var UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                string cryptFile = outputFile;
                var fsCrypt = new FileStream(cryptFile, FileMode.Create);

                var AesMngd = new AesManaged();

                var cs = new CryptoStream(fsCrypt,
                    AesMngd.CreateEncryptor(key, key),
                    CryptoStreamMode.Write);

                using (var fsIn = new FileStream(inputFile, FileMode.Open)) {
                    int data;
                    while ((data = fsIn.ReadByte()) != -1)
                        cs.WriteByte((byte)data);
                }
                cs.Close();
                fsCrypt.Close();
            } catch {
                Shared.MSGBOX(Shared.GetRes("#D.02#","Error"),"Encryption failed!",System.Windows.Application.Current.MainWindow);
            }
        }
开发者ID:RasyidUFA,项目名称:UFSJ,代码行数:27,代码来源:Shared.IO.cs

示例13: DecryptFile

        public static void DecryptFile(string inputFile, string outputFile, string password)
        {
            {
                //string password = @"myKey123"; // Your Key Here

                UnicodeEncoding UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                FileStream fsCrypt = new FileStream(inputFile, FileMode.Open);

                RijndaelManaged RMCrypto = new RijndaelManaged();

                CryptoStream cs = new CryptoStream(fsCrypt,
                                                   RMCrypto.CreateDecryptor(key, key),
                                                   CryptoStreamMode.Read);

                FileStream fsOut = new FileStream(outputFile, FileMode.Create);

                int data;
                while ((data = cs.ReadByte()) != -1)
                    fsOut.WriteByte((byte) data);

                fsOut.Close();
                cs.Close();
                fsCrypt.Close();

            }
        }
开发者ID:hkuntal,项目名称:TeamWorkManagement,代码行数:28,代码来源:Program.cs

示例14: DecryptFile

        internal static void DecryptFile(string inputFile, string outputFile, string password)
        {

            {
                var UE = new UnicodeEncoding();
                byte[] key = UE.GetBytes(password);

                var fsCrypt = new FileStream(inputFile, FileMode.Open);

                var RMCrypto = new AesManaged();

                var cs = new CryptoStream(fsCrypt,
                    RMCrypto.CreateDecryptor(key, key),
                    CryptoStreamMode.Read);

                var fsOut = new FileStream(outputFile, FileMode.Create);

                int data;
                while ((data = cs.ReadByte()) != -1)
                    fsOut.WriteByte((byte)data);

                fsOut.Close();
                cs.Close();
                fsCrypt.Close();

            }
        }
开发者ID:RasyidUFA,项目名称:UFSJ,代码行数:27,代码来源:Shared.IO.cs

示例15: Sha1

 public static string Sha1(this string input)
 {
     var provider = new SHA1CryptoServiceProvider();
     var encoding = new UnicodeEncoding();
     var bytehash = provider.ComputeHash(encoding.GetBytes(input));
     return Convert.ToBase64String(bytehash);
 }
开发者ID:jaceenet,项目名称:SirenMapper,代码行数:7,代码来源:StringExtensions.cs


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