public void Init( bool forSigning, ICipherParameters parameters) { this.forSigning = forSigning; AsymmetricKeyParameter k; if (parameters is ParametersWithRandom) { k = (AsymmetricKeyParameter)((ParametersWithRandom)parameters).Parameters; } else { k = (AsymmetricKeyParameter)parameters; } if (forSigning && !k.IsPrivate) { throw new InvalidKeyException("Signing Requires Private Key."); } if (!forSigning && k.IsPrivate) { throw new InvalidKeyException("Verification Requires Public Key."); } Reset(); dsaSigner.Init(forSigning, parameters); }
/// <summary> /// Initialise the signer for signing or verification. /// </summary> /// <param name="forSigning"></param> /// <param name="parameters"></param> /// <exception cref="InvalidKeyException"> /// Signing Requires Private Key. /// or /// Verification Requires Public Key. /// </exception> public void Init(bool forSigning, ICipherParameters parameters) { _forSigning = forSigning; IAsymmetricKeyParameter k; var parametersWithRandom = parameters as ParametersWithRandom; if (parametersWithRandom != null) { k = (AsymmetricKeyParameter)parametersWithRandom.Parameters; } else { k = (AsymmetricKeyParameter)parameters; } if (forSigning && !k.IsPrivate) { throw new InvalidKeyException("Signing Requires Private Key."); } if (!forSigning && k.IsPrivate) { throw new InvalidKeyException("Verification Requires Public Key."); } this.Reset(); _dsaSigner.Init(forSigning, parameters); }
public virtual void Init(bool forSigning, ICipherParameters parameters) { this.forSigning = forSigning; AsymmetricKeyParameter asymmetricKeyParameter = (!(parameters is ParametersWithRandom)) ? ((AsymmetricKeyParameter)parameters) : ((AsymmetricKeyParameter)((ParametersWithRandom)parameters).Parameters); if (forSigning && !asymmetricKeyParameter.IsPrivate) { throw new InvalidKeyException("Signing Requires Private Key."); } if (!forSigning && asymmetricKeyParameter.IsPrivate) { throw new InvalidKeyException("Verification Requires Public Key."); } Reset(); dsaSigner.Init(forSigning, parameters); }
private void DoTestHMacDetECDsa(IDsa detSigner, IDigest digest, byte[] data, ICipherParameters privKey, BigInteger r, BigInteger s) { byte[] m = new byte[digest.GetDigestSize()]; digest.BlockUpdate(data, 0, data.Length); digest.DoFinal(m, 0); detSigner.Init(true, privKey); BigInteger[] rs = detSigner.GenerateSignature(m); if (!r.Equals(rs[0])) { Fail("r value wrong"); } if (!s.Equals(rs[1])) { Fail("s value wrong"); } }