Open bian8021 opened 1 year ago
SM2 uses a user ID as a kind of context parameter. You will have to read about the algorithm for more details.
You can't use null, but you can just pass the privateKey (instead of a ParametersWithID) and the default user ID will be used. Note that anyone trying to verify your signature would need to agree on the user ID involved (whether an explicit one or the default).
@peterdettman looks like user ID is a mandatory parameter. could you provide code snippet how to pass private key without user ID?
@peterdettman any clue here?
I found following sample code to sign data with SM2 algorithm, why it has a userId parameter here, what the purpose for this parameter, can I pass null value here?
public static byte[] SignSm3WithSm2Asn1Rs(byte[] msg, byte[] userId, AsymmetricKeyParameter privateKey) { try { ISigner signer = SignerUtilities.GetSigner("SM3withSM2"); signer.Init(true, new ParametersWithID(privateKey, userId)); signer.BlockUpdate(msg, 0, msg.Length); byte[] sig = signer.GenerateSignature(); return sig; } catch (Exception e) { log.Error("SignSm3WithSm2Asn1Rs error: " + e.Message, e); return null; } }