[C#] 纯文本查看 复制代码
// 生成R=r*G
TBCryptoBigInteger r = null;
Random random = new SecureRandom();
do // Generate r
{
r = new TBCryptoBigInteger(this.ecdomainpsCDKey.N.BitLength, random);
}
while (r.SignValue == 0);
ECPoint R = this.ecdomainpsCDKey.G.Multiply(r);
// Hash = SHA1(data,Rx,Ry)
string hashStr = Sha1(31, rawKeyBytes, R.X.ToBigInteger().ToByteArray(), R.Y.ToBigInteger().ToByteArray());
TBCryptoBigInteger hashInt = new TBCryptoBigInteger(hashStr, 2);
// sig = r-Hash*D (mod n)
TBCryptoBigInteger sig = r.Subtract(hashInt.Multiply(this.ecDCDKey)).Mod(this.ecdomainpsCDKey.N);
[C#] 纯文本查看 复制代码
// 验证签名
X9ECParameters ecps = X962NamedCurves.GetByOid(X9ObjectIdentifiers.Prime256v1);
ECPublicKeyParameters pk = new ECPublicKeyParameters("ECDSA",
ecps.Curve.DecodePoint(Hex.Decode(KeyAttribute.GetKey(type.Assembly))),
new ECDomainParameters(ecps.Curve, ecps.G, ecps.N, ecps.H));
ISigner s = SignerUtilities.GetSigner("ECDSA");
s.Init(false, pk);
s.BlockUpdate(bytes, 0, dataLen);
if (s.VerifySignature(sig))
{
this.data = new byte[dataLen];
Array.Copy(bytes, 0, this.data, 0, data.Length);
}