簽名
1 // 生成R=r*G
2 TBCryptoBigInteger r = null;
3 Random random = new SecureRandom();
4 do // Generate r
5 {
6 r = new TBCryptoBigInteger(this.ecdomainpsCDKey.N.BitLength, random);
7 }
8 while (r.SignValue == 0);
9 ECPoint R = this.ecdomainpsCDKey.G.Multiply (r);
10 // Hash = SHA1(data,Rx,Ry)
11 string hashStr = Sha1(31, rawKeyBytes, R.X.ToBigInteger().ToByteArray(), R.Y.ToBigInteger().ToByteArray ());
12 TBCryptoBigInteger hashInt = new TBCryptoBigInteger(hashStr, 2);
13 // sig = r-Hash*D (mod n)
14 TBCryptoBigInteger sig = r.Subtract (hashInt.Multiply(this.ecDCDKey)).Mod(this.ecdomainpsCDKey.N);
驗證
1 // 驗證簽名
2 X9ECParameters ecps = X962NamedCurves.GetByOid (X9ObjectIdentifIErs.Prime256v1);
3 ECPublicKeyParameters pk = new ECPublicKeyParameters("ECDSA",
4 ecps.Curve.DecodePoint (Hex.Decode(KeyAttribute.GetKey(type.Assembly))),
5 new ECDomainParameters(ecps.Curve, ecps.G, ecps.N, ecps.H));
6 ISigner s = SignerUtilitIEs.GetSigner("ECDSA");
7 s.Init(false, pk);
8 s.BlockUpdate(bytes, 0, dataLen);
9 if (s.VerifySignature(sig))
10 {
11 this.data = new byte[dataLen];
12 Array.Copy(bytes, 0, this.data, 0, data.Length);
13 }
另外,關於BASE24,大整數,大家可以看看園子裡的文章。