public override void SetKey(AsymmetricAlgorithm p_key) { if (p_key is ElGamalManaged) { o_key = p_key as ElGamalManaged; } else { throw new ArgumentException("Qelesi nuk eshte instance e ElGamal Manages", "p_key"); } }
public override void SetKey(AsymmetricAlgorithm p_key) { if (p_key is ElGamalManaged) { o_key = p_key as ElGamalManaged; } else { throw new ArgumentException( "Key is not an instance of ElGamalManaged", "p_key"); } }
private void btnSign_Click(object sender, EventArgs e) { x_plaintextForSignature = Encoding.UTF8.GetBytes(txtSignPlaintext.Text); x_alg_signature.KeySize = int.Parse(cboKeySizes.SelectedValue.ToString()); x_xml_string_signature = x_alg_signature.ToXmlString(true); ElGamal x_sign_alg = new ElGamalManaged(); x_sign_alg.FromXmlString(x_alg_signature.ToXmlString(true)); x_signature = x_sign_alg.Sign(x_plaintextForSignature); txtSignedPlainText.Text = Convert.ToBase64String(x_signature); }
private void btnSign_Click(object sender, EventArgs e) { x_plaintextForSignature = Encoding.UTF8.GetBytes(txtSignPlaintext.Text); // Create an instance of the algorithm and generate some keys // set the key size - keep is small to speed up the tests x_alg_signature.KeySize = int.Parse(cboKeySizes.SelectedValue.ToString()); // extract and print the xml string (this will cause // a new key pair to be generated) string x_xml_string = x_alg_signature.ToXmlString(true); ElGamal x_sign_alg = new ElGamalManaged(); // set the keys - note that we export with the // private parameters since we are signing data x_sign_alg.FromXmlString(x_alg_signature.ToXmlString(true)); x_signature = x_sign_alg.Sign(x_plaintextForSignature); txtSignedPlainText.Text = Encoding.UTF8.GetString(x_signature); // verify the signature }
private void btnVerify_Click(object sender, EventArgs e) { x_plaintextForSignature = Encoding.UTF8.GetBytes(txtSignPlaintext.Text); ElGamal x_verify_alg = new ElGamalManaged(); x_verify_alg.FromXmlString(x_alg_signature.ToXmlString(false)); bool IsValid = x_verify_alg.VerifySignature(x_plaintextForSignature, x_signature); if (IsValid) { pbIsValid.Visible = true; pbIsValid.Image = Resources.Valid; } else { pbIsValid.Visible = true; pbIsValid.Image = Resources.InValid; } }