MCPcopy Index your code
hub / github.com/SeanDragon/protools / sign

Method sign

security/src/main/java/pro/tools/security/sm/SM2.java:491–512  ·  view source on GitHub ↗

签名 @param M 签名信息 @param IDA 签名方唯一标识 @param keyPair 签名方密钥对 @return 签名

(String M, String IDA, SM2KeyPair keyPair)

Source from the content-addressed store, hash-verified

489 * @return 签名
490 */
491 public Signature sign(String M, String IDA, SM2KeyPair keyPair) {
492 byte[] ZA = ZA(IDA, keyPair.getPublicKey());
493 byte[] M_ = join(ZA, M.getBytes());
494 BigInteger e = new BigInteger(1, sm3hash(M_));
495 // BigInteger k = new BigInteger(
496 // "6CB28D99 385C175C 94F94E93 4817663F C176D925 DD72B727 260DBAAE
497 // 1FB2F96F".replace(" ", ""), 16);
498 BigInteger k;
499 BigInteger r;
500 do {
501 k = random(n);
502 ECPoint p1 = G.multiply(k).normalize();
503 BigInteger x1 = p1.getXCoord().toBigInteger();
504 r = e.add(x1);
505 r = r.mod(n);
506 } while (r.equals(BigInteger.ZERO) || r.add(k).equals(n));
507
508 BigInteger s = ((keyPair.getPrivateKey().add(BigInteger.ONE).modInverse(n))
509 .multiply((k.subtract(r.multiply(keyPair.getPrivateKey()))).mod(n))).mod(n);
510
511 return new Signature(r, s);
512 }
513
514 /**
515 * 验签

Callers

nothing calls this directly

Calls 8

ZAMethod · 0.95
joinMethod · 0.95
sm3hashMethod · 0.95
randomMethod · 0.95
addMethod · 0.80
getPublicKeyMethod · 0.45
equalsMethod · 0.45
getPrivateKeyMethod · 0.45

Tested by

no test coverage detected