-
-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sm2签名时z值不参与如何处理 #78
Comments
这个参考网址打不开 |
更新了下地址,应该是url带着汉字的问题,大佬再试下看。 |
好,我周末有空看下,平时没时间哈。你要着急的话也可以自己先研究一下。 |
嗯感谢大佬 |
看了下BC的代码(最新的1.70版本),基于BC可能控制不了要不要算Z,它的实现里没有提供控制这个行为的参数。 // 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);
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
硬件密码介质,如密码机等,在签名过程中z值不参与,请教下基于bc库如何实现呢?
签名结果不带z值的验签,可参考
https://i.goto327.top/CryptTools/SM2.aspx
进行不带Z值签名验证。
请大佬指导下。
The text was updated successfully, but these errors were encountered: