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


C# SortedDictionary.ToStringDeferred方法代码示例

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


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

示例1: GetReturnToSignature

		/// <summary>
		/// Gets the return to signature.
		/// </summary>
		/// <param name="returnTo">The return to.</param>
		/// <param name="cryptoKey">The crypto key.</param>
		/// <returns>
		/// The generated signature.
		/// </returns>
		/// <remarks>
		/// Only the parameters in the return_to URI are signed, rather than the base URI
		/// itself, in order that OPs that might change the return_to's implicit port :80 part
		/// or other minor changes do not invalidate the signature.
		/// </remarks>
		private byte[] GetReturnToSignature(Uri returnTo, CryptoKey cryptoKey = null) {
			Requires.NotNull(returnTo, "returnTo");

			// Assemble the dictionary to sign, taking care to remove the signature itself
			// in order to accurately reproduce the original signature (which of course didn't include
			// the signature).
			// Also we need to sort the dictionary's keys so that we sign in the same order as we did
			// the last time.
			var returnToParameters = HttpUtility.ParseQueryString(returnTo.Query);
			returnToParameters.Remove(ReturnToSignatureParameterName);
			var sortedReturnToParameters = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
			foreach (string key in returnToParameters) {
				sortedReturnToParameters.Add(key, returnToParameters[key]);
			}

			Logger.Bindings.DebugFormat("ReturnTo signed data: {0}{1}", Environment.NewLine, sortedReturnToParameters.ToStringDeferred());

			// Sign the parameters.
			byte[] bytesToSign = KeyValueFormEncoding.GetBytes(sortedReturnToParameters);
			byte[] signature;
			try {
				if (cryptoKey == null) {
					cryptoKey = this.cryptoKeyStore.GetKey(SecretUri.AbsoluteUri, returnToParameters[ReturnToSignatureHandleParameterName]);
					ErrorUtilities.VerifyProtocol(
						cryptoKey != null,
						MessagingStrings.MissingDecryptionKeyForHandle,
						SecretUri.AbsoluteUri,
						returnToParameters[ReturnToSignatureHandleParameterName]);
				}

				using (var signer = HmacAlgorithms.Create(HmacAlgorithms.HmacSha256, cryptoKey.Key)) {
					signature = signer.ComputeHash(bytesToSign);
				}
			} catch (ProtocolException ex) {
				throw ErrorUtilities.Wrap(ex, OpenIdStrings.MaximumAuthenticationTimeExpired);
			}

			return signature;
		}
开发者ID:randalls,项目名称:DotNetOpenAuth,代码行数:52,代码来源:ReturnToSignatureBindingElement.cs

示例2: GetReturnToSignature

        /// <summary>
        /// Gets the return to signature.
        /// </summary>
        /// <param name="returnTo">The return to.</param>
        /// <returns>The generated signature.</returns>
        /// <remarks>
        /// Only the parameters in the return_to URI are signed, rather than the base URI
        /// itself, in order that OPs that might change the return_to's implicit port :80 part
        /// or other minor changes do not invalidate the signature.
        /// </remarks>
        private string GetReturnToSignature(Uri returnTo)
        {
            ErrorUtilities.VerifyArgumentNotNull(returnTo, "returnTo");

            // Assemble the dictionary to sign, taking care to remove the signature itself
            // in order to accurately reproduce the original signature (which of course didn't include
            // the signature).
            // Also we need to sort the dictionary's keys so that we sign in the same order as we did
            // the last time.
            var returnToParameters = HttpUtility.ParseQueryString(returnTo.Query);
            returnToParameters.Remove(ReturnToSignatureParameterName);
            var sortedReturnToParameters = new SortedDictionary<string, string>(StringComparer.OrdinalIgnoreCase);
            foreach (string key in returnToParameters) {
                sortedReturnToParameters.Add(key, returnToParameters[key]);
            }

            Logger.Bindings.DebugFormat("ReturnTo signed data: {0}{1}", Environment.NewLine, sortedReturnToParameters.ToStringDeferred());

            // Sign the parameters.
            byte[] bytesToSign = KeyValueFormEncoding.GetBytes(sortedReturnToParameters);
            byte[] signature;
            try {
                signature = this.secretManager.Sign(bytesToSign, returnToParameters[ReturnToSignatureHandleParameterName]);
            } catch (ProtocolException ex) {
                throw ErrorUtilities.Wrap(ex, OpenIdStrings.MaximumAuthenticationTimeExpired);
            }
            string signatureBase64 = Convert.ToBase64String(signature);
            return signatureBase64;
        }
开发者ID:vrushalid,项目名称:dotnetopenid,代码行数:39,代码来源:ReturnToSignatureBindingElement.cs


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