本文整理汇总了C#中Association.Sign方法的典型用法代码示例。如果您正苦于以下问题:C# Association.Sign方法的具体用法?C# Association.Sign怎么用?C# Association.Sign使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Association
的用法示例。
在下文中一共展示了Association.Sign方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetSignature
/// <summary>
/// Calculates the signature for a given message.
/// </summary>
/// <param name="signedMessage">The message to sign or verify.</param>
/// <param name="association">The association to use to sign the message.</param>
/// <returns>The calculated signature of the method.</returns>
private string GetSignature(ITamperResistantOpenIdMessage signedMessage, Association association) {
Contract.Requires<ArgumentNullException>(signedMessage != null);
Contract.Requires<ArgumentException>(!String.IsNullOrEmpty(signedMessage.SignedParameterOrder));
Contract.Requires<ArgumentNullException>(association != null);
// Prepare the parts to sign, taking care to replace an openid.mode value
// of check_authentication with its original id_res so the signature matches.
MessageDictionary dictionary = this.Channel.MessageDescriptions.GetAccessor(signedMessage);
var parametersToSign = from name in signedMessage.SignedParameterOrder.Split(',')
let prefixedName = Protocol.V20.openid.Prefix + name
select new KeyValuePair<string, string>(name, dictionary[prefixedName]);
byte[] dataToSign = KeyValueFormEncoding.GetBytes(parametersToSign);
string signature = Convert.ToBase64String(association.Sign(dataToSign));
if (Logger.Signatures.IsDebugEnabled) {
Logger.Signatures.DebugFormat(
"Signing these message parts: {0}{1}{0}Base64 representation of signed data: {2}{0}Signature: {3}",
Environment.NewLine,
parametersToSign.ToStringDeferred(),
Convert.ToBase64String(dataToSign),
signature);
}
return signature;
}
示例2: GetSignature
/// <summary>
/// Calculates the signature for a given message.
/// </summary>
/// <param name="signedMessage">The message to sign or verify.</param>
/// <param name="association">The association to use to sign the message.</param>
/// <returns>The calculated signature of the method.</returns>
private string GetSignature(ITamperResistantOpenIdMessage signedMessage, Association association)
{
ErrorUtilities.VerifyArgumentNotNull(signedMessage, "signedMessage");
ErrorUtilities.VerifyNonZeroLength(signedMessage.SignedParameterOrder, "signedMessage.SignedParameterOrder");
ErrorUtilities.VerifyArgumentNotNull(association, "association");
// Prepare the parts to sign, taking care to replace an openid.mode value
// of check_authentication with its original id_res so the signature matches.
MessageDictionary dictionary = this.Channel.MessageDescriptions.GetAccessor(signedMessage);
var parametersToSign = from name in signedMessage.SignedParameterOrder.Split(',')
let prefixedName = Protocol.V20.openid.Prefix + name
select new KeyValuePair<string, string>(name, dictionary[prefixedName]);
byte[] dataToSign = KeyValueFormEncoding.GetBytes(parametersToSign);
string signature = Convert.ToBase64String(association.Sign(dataToSign));
if (Logger.Signatures.IsDebugEnabled) {
Logger.Signatures.DebugFormat(
CultureInfo.InvariantCulture,
"Signing these message parts: {0}{1}{0}Base64 representation of signed data: {2}{0}Signature: {3}",
Environment.NewLine,
parametersToSign.ToStringDeferred(),
Convert.ToBase64String(dataToSign),
signature);
}
return signature;
}