本文整理汇总了C#中ISigner.GenerateSignature方法的典型用法代码示例。如果您正苦于以下问题:C# ISigner.GenerateSignature方法的具体用法?C# ISigner.GenerateSignature怎么用?C# ISigner.GenerateSignature使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISigner
的用法示例。
在下文中一共展示了ISigner.GenerateSignature方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: checkSignature
private void checkSignature(
int size,
ECPrivateKeyParameters sKey,
ECPublicKeyParameters vKey,
ISigner sgr,
SecureRandom k,
byte[] message,
BigInteger r,
BigInteger s)
{
sgr.Init(true, new ParametersWithRandom(sKey, k));
sgr.BlockUpdate(message, 0, message.Length);
byte[] sigBytes = sgr.GenerateSignature();
sgr.Init(false, vKey);
sgr.BlockUpdate(message, 0, message.Length);
if (!sgr.VerifySignature(sigBytes))
{
Fail(size + " bit EC verification failed");
}
BigInteger[] sig = derDecode(sigBytes);
if (!r.Equals(sig[0]))
{
Fail(size + "bit"
+ ": r component wrong." + SimpleTest.NewLine
+ " expecting: " + r + SimpleTest.NewLine
+ " got : " + sig[0]);
}
if (!s.Equals(sig[1]))
{
Fail(size + "bit"
+ ": s component wrong." + SimpleTest.NewLine
+ " expecting: " + s + SimpleTest.NewLine
+ " got : " + sig[1]);
}
}
示例2: DKIMSign
public void DKIMSign(ISigner signer, CanonicalizationType headerCanonicalization, CanonicalizationType bodyCanonicalization, HashingAlgorithm hashAlgorithm, string domain, string selector)
{
if (IsSigned)
throw new InvalidOperationException("Message already have DKIM header.");
IsSigned = true;
string hashtype = hashAlgorithm == HashingAlgorithm.RSASha1 ? "sha1" : "sha256";
StringBuilder dkim = new StringBuilder(300)
.Append("v=1;") // version
.Append("a=").Append("rsa-").Append(hashtype).Append(";") // hash algorithm
.Append("c=").Append(string.Format("{0}/{1}", headerCanonicalization, bodyCanonicalization).ToLower()).Append(";") // canonicalization types headers/body
.Append("d=").Append(domain).Append(";") // domain for diim check
.Append("s=").Append(selector).Append(";") // TXT record selector
.Append("t=").Append(Convert.ToInt64((DateTime.Now.ToUniversalTime() - DateTime.SpecifyKind(DateTime.Parse("00:00:00 January 1, 1970"), DateTimeKind.Utc)).TotalSeconds).ToString()).Append(";") // creation time
.Append("bh=").Append(GetBodyHash(bodyCanonicalization, hashtype)).Append(";"); // body hash
var headers = ComputedHeaders;
List<string> h = new List<string>();
foreach (string header in headers)
foreach (string value in headers.GetValues(header))
h.Add(header);
dkim.Append("h=").Append(string.Join(":", h)).Append(";") // headers for hashing
.Append("b="); // signature data
var canonialized = DKIMCanonicalizer.CanonicalizeHeader(headerCanonicalization, headers) + "dkim-signature:" + dkim.ToString();
var bytes = (HeadersEncoding ?? Encoding.UTF8).GetBytes(canonialized);
lock (signer)
{
signer.BlockUpdate(bytes, 0, bytes.Length);
bytes = signer.GenerateSignature();//computing signature
signer.Reset();
}
dkim.Append(Convert.ToBase64String(bytes));
Headers.Add("dkim-signature", dkim.ToString());// adding DKIM header
}