private void signatureVerifyBtn_Click(object sender, EventArgs e) { var ready = true; if (string.IsNullOrWhiteSpace(signatureVerifySignatureFile.Text)) { MessageBox.Show("Choose a signature file", "Choose a signature file", MessageBoxButtons.OK, MessageBoxIcon.Warning); ready = false; } if (string.IsNullOrWhiteSpace(signatureVerifyPublicKey.Text)) { signatureVerifyPublicKey.Text = _initialDirectory + "RSA_public.txt"; } if (ready) { var verified = DigitalSignature.VerifySignature(signatureVerifySignatureFile.Text, int.Parse(rsaKeysSize.Text), signatureVerifyPublicKey.Text); if (verified) { MessageBox.Show("Sender is verified", "Verified", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("Sender is not verified", "Not verified", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
private void signatureCreateSignature_Click(object sender, EventArgs e) { var ready = true; if (string.IsNullOrWhiteSpace(signatureSignPlain.Text)) { MessageBox.Show("Choose a plain text file", "Choose a plain text file", MessageBoxButtons.OK, MessageBoxIcon.Warning); ready = false; } if (string.IsNullOrWhiteSpace(signatureSignPrivateKey.Text)) { signatureSignPrivateKey.Text = _initialDirectory + "RSA_private.txt"; } if (string.IsNullOrWhiteSpace(signatureSignSignature.Text)) { signatureSignSignature.Text = _initialDirectory + "Signature.txt"; } if (ready) { DigitalSignature.CreateSignature(signatureSignPlain.Text, int.Parse(rsaKeysSize.Text), signatureSignPrivateKey.Text, signatureSignSignature.Text); } }
public static void CreateSignedEnvelope(string plainTextFile, int keySize, string receiverPublicKeyFilePath, string senderPrivateKeyFilePath, string outputFilePath) { var tmpEnvelopeFilePath = Environment.CurrentDirectory + @"\Files\tmp\envelope_tmp.txt"; DigitalEnvelope.CreateEnvelope(plainTextFile, keySize, receiverPublicKeyFilePath, tmpEnvelopeFilePath); DigitalSignature.CreateEnvelopeSignature(tmpEnvelopeFilePath, keySize, senderPrivateKeyFilePath, outputFilePath); }
public static bool OpenSignedEnvelope(string signedEnvelopeFilePath, int keySize, string receiverPrivateKeyFilePath, string senderPublicKeyFilePath, string outputFilePath) { var verified = DigitalSignature.VerifyEnvelopeSignature(signedEnvelopeFilePath, keySize, senderPublicKeyFilePath); var file = FileOperations.ReadFromTextFile(signedEnvelopeFilePath); var fileSplit = file.Split(new char[0], StringSplitOptions.RemoveEmptyEntries); var keyBytes = Converter.HexStringToBytes(fileSplit[4]); var messageBytes = Converter.HexStringToBytes(fileSplit[6]); DigitalEnvelope.ReadEnvelope(keyBytes, messageBytes, keySize, receiverPrivateKeyFilePath, outputFilePath); return(verified); }