private void buttonBrowseFile1_Click(object sender, EventArgs e) { FileDialog fd = null; OpenFileDialog ofd; SaveFileDialog sfd; KeyFileType kft = KeyFileType.PrivateKey; switch (m_command) { case ConfigDialogCommand.Configure: ofd = new OpenFileDialog(); ofd.Filter = Properties.Resources.FileDialogFilterKeys; ofd.FilterIndex = 0; ofd.Multiselect = false; ofd.RestoreDirectory = true; kft = KeyFileType.PublicKey; fd = ofd; break; case ConfigDialogCommand.SignDeployment: ofd = new OpenFileDialog(); ofd.Filter = Properties.Resources.FileDialogFilterDeploymentFiles; ofd.FilterIndex = 0; ofd.Multiselect = false; ofd.RestoreDirectory = true; kft = KeyFileType.HexFile; fd = ofd; break; case ConfigDialogCommand.CreateDeployment: sfd = new SaveFileDialog(); sfd.Filter = Properties.Resources.FileDialogFilterDeploymentFiles; sfd.FilterIndex = 0; sfd.RestoreDirectory = true; sfd.Title = Properties.Resources.CreateDeploymentTitle; kft = KeyFileType.HexFile; fd = sfd; break; } if (DialogResult.OK == fd.ShowDialog(this)) { comboBoxFile1.Text = fd.FileName; if (fd is OpenFileDialog) { if (!CheckFile(comboBoxFile1.Text, kft)) { comboBoxFile1.SelectAll(); } } } }
private bool CheckFile(string file, KeyFileType type) { int size = 0; string errorMessage = ""; switch (type) { case KeyFileType.PublicKey: case KeyFileType.PrivateKey: try { KeyPair keyPair = m_keyTool.LoadKeyPair(file); byte[] key = (type == KeyFileType.PublicKey) ? keyPair.PublicKey : keyPair.PrivateKey; size = key.Length; } catch { MessageBox.Show(this, string.Format(Properties.Resources.ErrorFileInvalid, file), Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } errorMessage = Properties.Resources.ErrorKeyFileInvalid; break; case KeyFileType.Signature: try { FileInfo fi = new FileInfo(file); size = (int)fi.Length; } catch { MessageBox.Show(this, string.Format(Properties.Resources.ErrorFileInvalid, file), Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } errorMessage = Properties.Resources.ErrorSignatureFileInvalid; break; case KeyFileType.HexFile: break; default: System.Diagnostics.Debug.Assert(false); break; } if (!CheckKeySize(size, type)) { MessageBox.Show(this, string.Format(errorMessage, Path.GetFileName(file)), Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } return(true); }
private bool CheckKeySize(int size, KeyFileType type) { switch (type) { case KeyFileType.PublicKey: return size == MFKeyConfig.PublicKeySize; case KeyFileType.PrivateKey: return size == MFKeyConfig.PrivateKeySize; case KeyFileType.Signature: return size == MFKeyConfig.SignatureSize; case KeyFileType.HexFile: return true; } return false; }
private bool CheckKeySize(int size, KeyFileType type) { switch (type) { case KeyFileType.PublicKey: return(size == MFKeyConfig.PublicKeySize); case KeyFileType.PrivateKey: return(size == MFKeyConfig.PrivateKeySize); case KeyFileType.Signature: return(size == MFKeyConfig.SignatureSize); case KeyFileType.HexFile: return(true); } return(false); }
private bool CheckFile(string file, KeyFileType type) { int size = 0; string errorMessage = ""; switch (type) { case KeyFileType.PublicKey: case KeyFileType.PrivateKey: try { KeyPair keyPair = m_keyTool.LoadKeyPair(file); byte[] key = (type == KeyFileType.PublicKey) ? keyPair.PublicKey : keyPair.PrivateKey; size = key.Length; } catch { MessageBox.Show(this, string.Format(Properties.Resources.ErrorFileInvalid, file), Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } errorMessage = Properties.Resources.ErrorKeyFileInvalid; break; case KeyFileType.Signature: try { FileInfo fi = new FileInfo(file); size = (int)fi.Length; } catch { MessageBox.Show(this, string.Format(Properties.Resources.ErrorFileInvalid, file), Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } errorMessage = Properties.Resources.ErrorSignatureFileInvalid; break; case KeyFileType.HexFile: break; default: System.Diagnostics.Debug.Assert(false); break; } if(!CheckKeySize(size, type)) { MessageBox.Show(this, string.Format(errorMessage, Path.GetFileName(file)), Properties.Resources.Error, MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } return true; }
private bool CheckKey(byte[] key, KeyFileType type) { return CheckKeySize(key.Length, type); }
private bool CheckKey(byte[] key, KeyFileType type) { return(CheckKeySize(key.Length, type)); }