Giter Club home page Giter Club logo

Comments (5)

ZZMarquis avatar ZZMarquis commented on September 3, 2024

这个参考网址打不开

from gmhelper.

Jeery-Wang avatar Jeery-Wang commented on September 3, 2024

更新了下地址,应该是url带着汉字的问题,大佬再试下看。
签名时候,后面有个选项是否计算z值,默认是带的,和用bc库签出来的结果可以互相验签。
当z值不参与运算时,用bc库应该怎么签名和验签呢,请帮忙看下。

from gmhelper.

ZZMarquis avatar ZZMarquis commented on September 3, 2024

好,我周末有空看下,平时没时间哈。你要着急的话也可以自己先研究一下。

from gmhelper.

Jeery-Wang avatar Jeery-Wang commented on September 3, 2024

嗯感谢大佬

from gmhelper.

ZZMarquis avatar ZZMarquis commented on September 3, 2024

看了下BC的代码(最新的1.70版本),基于BC可能控制不了要不要算Z,它的实现里没有提供控制这个行为的参数。
不过想做的话应该也简单,SM2Signer的代码还是相对牵扯其他东西较少的,可以拷贝出来自己改改应该就可以。

    // org.bouncycastle.crypto.signers.SM2Signer

    public void init(boolean forSigning, CipherParameters param)
    {
        CipherParameters baseParam;
        byte[] userID;

        if (param instanceof ParametersWithID)
        {
            baseParam = ((ParametersWithID)param).getParameters();
            userID = ((ParametersWithID)param).getID();

            if (userID.length >= 8192)
            {
                throw new IllegalArgumentException("SM2 user ID must be less than 2^16 bits long");
            }
        }
        else
        {
            baseParam = param;
            // the default value, string value is "1234567812345678"
            userID = Hex.decodeStrict("31323334353637383132333435363738");
        }

        if (forSigning)
        {
            if (baseParam instanceof ParametersWithRandom)
            {
                ParametersWithRandom rParam = (ParametersWithRandom)baseParam;

                ecKey = (ECKeyParameters)rParam.getParameters();
                ecParams = ecKey.getParameters();
                kCalculator.init(ecParams.getN(), rParam.getRandom());
            }
            else
            {
                ecKey = (ECKeyParameters)baseParam;
                ecParams = ecKey.getParameters();
                kCalculator.init(ecParams.getN(), CryptoServicesRegistrar.getSecureRandom());
            }
            pubPoint = createBasePointMultiplier().multiply(ecParams.getG(), ((ECPrivateKeyParameters)ecKey).getD()).normalize();
        }
        else
        {
            ecKey = (ECKeyParameters)baseParam;
            ecParams = ecKey.getParameters();
            pubPoint = ((ECPublicKeyParameters)ecKey).getQ();
        }
        
        // TODO : 应该在这里加个if判断决定要不要执行后面的两行代码即可
        z = getZ(userID);
        digest.update(z, 0, z.length);
    }

from gmhelper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.