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


C# System.Text.UTF8Encoding.GetBytes方法代码示例

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


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

示例1: TestIssuerSetupParameters

        public void TestIssuerSetupParameters()
        {
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();

            byte[][] A = new byte[][] { encoding.GetBytes("attribute value") };
            byte[] TI = encoding.GetBytes("TI value");
            IssuerSetupParameters isp = new IssuerSetupParameters();
            isp.GroupConstruction = GroupType.Subgroup;
            isp.UidP = encoding.GetBytes("UIDP value");
            isp.E = new byte[] { 1 };
            IssuerKeyAndParameters ikap = isp.Generate();

            ikap.IssuerParameters.Verify();

            // invalidate the issuer parameters

            IssuerParameters ip = ikap.IssuerParameters;
            SubgroupGroupElement sgG0 = (SubgroupGroupElement) ip.G[0];
            byte[] g0Bytes = ip.G[0].GetEncoded();
            g0Bytes[g0Bytes.Length - 1]++;
            ip.G[0] = (SubgroupGroupElement) ip.Gq.CreateGroupElement(g0Bytes);

            try
            {
                ip.Verify();
                Assert.Fail();
            }
            catch (InvalidUProveArtifactException) { }
            
        }
开发者ID:Fiware,项目名称:security.P2abcengine,代码行数:30,代码来源:IssuerTest.cs

示例2: buildSignature

        private static string buildSignature(NameValueCollection queryString)
        {
            try
            {

            //// The HMAC secret as configured in the skin
                string hmacSecret = Globals.Instance.settings["PayPalhmacSecret"];

            //// Generate the signing string
            string signingString = queryString["paymentAmount"] + queryString["currencyCode"] +
                                   queryString["shipBeforeDate"] + queryString["merchantReference"] +
                                   queryString["skinCode"] + queryString["merchantAccount"] +
                                   queryString["sessionValidity"] + queryString["allowedMethods"] + queryString["merchantReturnData"];

            //// Values are always transferred using UTF-8 encoding
            var encoding = new System.Text.UTF8Encoding();

            //// Calculate the HMAC
            var myhmacsha1 = new HMACSHA1(encoding.GetBytes(hmacSecret));
            return Convert.ToBase64String(myhmacsha1.ComputeHash(encoding.GetBytes(signingString)));
                }
            catch (Exception exp)
            {
                log.Error(exp);
                throw;
            }
        }
开发者ID:HarryMcCarney,项目名称:HackandCraft,代码行数:27,代码来源:PaypalBuilder.cs

示例3: EncryptString

        /// <summary>
        /// EncryptString
        /// </summary>
        /// <param name="message"></param>
        /// <param name="passphrase"></param>
        /// <returns></returns>
        public static string EncryptString(string message)
        {
            byte[] results;
            var utf8 = new System.Text.UTF8Encoding();

            var hashProvider = new MD5CryptoServiceProvider();
            var tdesKey = hashProvider.ComputeHash(utf8.GetBytes(Pass));

            var tdesAlgorithm = new TripleDESCryptoServiceProvider
                {
                    Key = tdesKey,
                    Mode = CipherMode.ECB,
                    Padding = PaddingMode.PKCS7
                };

            var dataToEncrypt = utf8.GetBytes(message);

            try
            {
                var encryptor = tdesAlgorithm.CreateEncryptor();
                results = encryptor.TransformFinalBlock(dataToEncrypt, 0, dataToEncrypt.Length);
            }
            finally
            {
                tdesAlgorithm.Clear();
                hashProvider.Clear();
            }

            return Convert.ToBase64String(results);
        }
开发者ID:nhanthieugia,项目名称:BSC.ServiceAPI,代码行数:36,代码来源:CommonLib.cs

示例4: MakeRequest

        public void MakeRequest(string type, string platform, string reqjsondata)
        {
            System.Text.UTF8Encoding en = new System.Text.UTF8Encoding();

            string secret = Configs.Secret;

            string uri = "http://api.bf3stats.com/" + platform + "/" + type + "/";
            WebClient wc = new WebClient();
            wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";

            if (type == "setupkey")
            {
                wc.UploadStringCompleted += new UploadStringCompletedEventHandler(completed_register);
            }
            else
            {
                wc.UploadStringCompleted += new UploadStringCompletedEventHandler(completed_update);
                secret = Configs.GetAPIkey();
            }

            System.Security.Cryptography.HMACSHA256 hmac = new System.Security.Cryptography.HMACSHA256(en.GetBytes(secret));

            Byte[] bytes = en.GetBytes(reqjsondata);
            string encodedRequest = Convert.ToBase64String(bytes).Replace('+', '-').Replace('/', '_').Replace("=", "");

            byte[] hashVal = hmac.ComputeHash(en.GetBytes(encodedRequest));
            string signature = Convert.ToBase64String(hashVal).Replace('+', '-').Replace('/', '_').Replace("=", "");

            string query = "data=" + encodedRequest + "&sig=" + signature;
            wc.UploadStringAsync(new Uri(uri), "POST", query);
        }
开发者ID:graboskyc,项目名称:BFStats,代码行数:31,代码来源:SignedRequest.cs

示例5: Encrypt

        /// encrypt a string message using a secret key that is known to both sender and recipient only;
        /// need to give the initialization vector to the recipient as well;
        static public bool Encrypt(byte[] ASecretKey, string AMessage, out string AEncryptedMessage, out string AInitializationVector)
        {
            Rijndael alg = new RijndaelManaged();

            alg.Key = ASecretKey;

            alg.GenerateIV();

            MemoryStream ms = new MemoryStream();

            CryptoStream encryptStream = new CryptoStream(
                ms,
                alg.CreateEncryptor(),
                CryptoStreamMode.Write);

            System.Text.UTF8Encoding enc = new System.Text.UTF8Encoding();
            byte[] toEncryptBytes = enc.GetBytes(AMessage);
            encryptStream.Write(toEncryptBytes, 0, toEncryptBytes.Length);
            encryptStream.Close();

            AEncryptedMessage = Convert.ToBase64String(ms.ToArray());
            AInitializationVector = Convert.ToBase64String(alg.IV);

            return true;
        }
开发者ID:Davincier,项目名称:openpetra,代码行数:27,代码来源:Encryption.cs

示例6: ComputeHashString

 protected string ComputeHashString(string rawString)
 {
     System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
     SHA256 hashM = new SHA256Managed();
     return encoding.GetString(hashM.ComputeHash(encoding.GetBytes(rawString))).
         Replace(',', '.').Replace('\r', '.').Replace('\n', '.');
 }
开发者ID:ne-sachirou,项目名称:yUsin-1,代码行数:7,代码来源:DatasData.cs

示例7: CompressContent

        /// <summary>
        /// Compress an string using ZIP
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static byte[] CompressContent(string contentToZip)
        {

            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            byte[] buff = encoding.GetBytes(contentToZip);

            try
            {
                using (MemoryStream stream = new MemoryStream())
                {
                    using (ZipOutputStream zipout = new ZipOutputStream(stream))
                    {
                        zipout.SetLevel(9);
                        ZipEntry entry = new ZipEntry("zipfile.zip");
                        entry.DateTime = DateTime.Now;
                        zipout.PutNextEntry(entry);
                        zipout.Write(buff, 0, buff.Length);
                        zipout.Finish();
                        byte[] outputbyte = new byte[(int)stream.Length];
                        stream.Position = 0;
                        stream.Read(outputbyte, 0, (int)stream.Length);
                        return outputbyte;
                    }

                }
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
                return null;
            }
        }
开发者ID:Chanicua,项目名称:GoogleHC,代码行数:37,代码来源:CompressionHelper.cs

示例8: getHash

		private string getHash(string s)
		{
			var csp = new System.Security.Cryptography.SHA256Managed();
			var utf8Encoding = new System.Text.UTF8Encoding();
			byte[] result = csp.ComputeHash(utf8Encoding.GetBytes(s));
			return Convert.ToBase64String(result)+"\n";
		}
开发者ID:LearningRegistry,项目名称:LR.Net,代码行数:7,代码来源:CryptoUtils.cs

示例9: WriteLongString

 public void WriteLongString(string str)
 {
     var encoding = new System.Text.UTF8Encoding();
     var bytes = encoding.GetBytes(str);
     WriteInt32(bytes.Length);
     _base.Write(bytes);
 }
开发者ID:joaquincasares,项目名称:csharp-driver,代码行数:7,代码来源:BEBinaryWriter.cs

示例10: EncryptData

 /// <summary>
 /// MD5 Hash
 /// </summary>
 /// <param name="data"></param>
 /// <returns></returns>
 private static byte[] EncryptData(string data)
 {
     var md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
     var encoder = new System.Text.UTF8Encoding();
     var hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
     return hashedBytes;
 }
开发者ID:nhanthieugia,项目名称:BSC.ServiceAPI,代码行数:12,代码来源:CommonLib.cs

示例11: encryptData

 public static byte[] encryptData(string data)
 {
     System.Security.Cryptography.MD5CryptoServiceProvider md5Hasher = new System.Security.Cryptography.MD5CryptoServiceProvider();
     byte[] hashedBytes;
     System.Text.UTF8Encoding encoder = new System.Text.UTF8Encoding();
     hashedBytes = md5Hasher.ComputeHash(encoder.GetBytes(data));
     return hashedBytes;
 }
开发者ID:typham,项目名称:HoiChuSinhSoSinh,代码行数:8,代码来源:Exts.cs

示例12: StrToByteArray

 public static byte[] StrToByteArray(string str)
 {
     System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
     byte[] s = encoding.GetBytes(str);
     byte[] r = new byte[s.Length + 1]; // null terminator
     for (int i = 0; i < s.Length; i++) { r[i] = s[i]; }
     return r;
 }
开发者ID:Dracar,项目名称:samp-dotnet-script-api,代码行数:8,代码来源:DataStream.cs

示例13: LoadBytes

        public static X509Certificate2 LoadBytes(string certificate)
        {
            if (string.IsNullOrWhiteSpace(certificate))
                throw new ArgumentNullException("certificate");

            var encoding = new System.Text.UTF8Encoding();
            return new X509Certificate2(encoding.GetBytes(certificate));
        }
开发者ID:hallatore,项目名称:ITfoxtec.SAML2,代码行数:8,代码来源:CertificateUtil.cs

示例14: ComputeHash

 public string ComputeHash(string str)
 {
     var md5 = MD5.Create();
     var encoding = new System.Text.UTF8Encoding();
     var encodedString = encoding.GetBytes(str);
     var hashBytes = md5.ComputeHash(encodedString);
     var deEncodedHash = encoding.GetChars(hashBytes);
     return new string(deEncodedHash);
 }
开发者ID:ExaurovNM,项目名称:BinaryStudion.OurFaces,代码行数:9,代码来源:Hasher.cs

示例15: WriteString

        public void WriteString(String value)
        {
            System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
            byte[] b = encoding.GetBytes(value);

            WriteInt32(b.Length); //Write the String length

            WriteBytes(b);
        }
开发者ID:devedse,项目名称:TurtleTurner2000,代码行数:9,代码来源:DeveOutgoingMessage.cs


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