private void btnKript_Click(object sender, EventArgs e) { int sizeN = int.Parse(txtNoData.Text); int sizeM = int.Parse(txtNoGen.Text); byte[] data = new byte[sizeM + sizeN]; byte[] generator = new byte[sizeM]; char[] dataPom = txtData.Text.ToCharArray(); char[] genPom = txtGenerator.Text.ToCharArray(); for (int i = 0; i < sizeN; i++) { data[i] = Convert.ToByte(dataPom[i]); } for (int i = 0; i < sizeM - 1; i++) { data[sizeN + i] = 0; } for (int i = 0; i < sizeM; i++) { generator[i] = Convert.ToByte(genPom[i]); } CRCAlgorithm c = new CRCAlgorithm(sizeN, sizeM, data, generator); byte[] crc = c.Crypt(data); string s = ""; for (int i = 0; i < crc.Length; i++) { s += crc[i].ToString(); } txtGen.Text = s; }
private void btnKriptujFile_Click(object sender, EventArgs e) { if (fileForCryptPath.Equals("")) { MessageBox.Show("File isn't selected!", "Missing file!", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } byte[] file = null; file = File.ReadAllBytes(fileForCryptPath); byte[] cryptedFile = algorithm.Crypt(file); File.WriteAllBytes(@".\\Crypted\\" + fileForCryptName + fileExtension, cryptedFile); if (checkCloud.Checked) { var cloudProxy = new CryptoServiceClient(); using (var stream = new FileStream(@".\\Crypted\\" + fileForCryptName + fileExtension, FileMode.Open, FileAccess.Read)) { bool resultOfUpload = cloudProxy.UploadFile(fileForCryptName + fileExtension, stream); if (resultOfUpload == true) { MessageBox.Show("File uploaded to cloud!", "Successfull upload!", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("There was error while trying to upload file!", "Error while uploading!", MessageBoxButtons.OK, MessageBoxIcon.Error); } } cloudProxy.Close(); } }