private void EncryptPass(object sender, RoutedEventArgs e) { var bytes = File.ReadAllBytes(pathPassTB.Text); var open_key = File.ReadAllLines(SenderPath + @"\open_key.txt"); var D = new BigInteger(open_key[0].Split(' ').Select(a => byte.Parse(a.ToString(), NumberStyles.HexNumber)).ToArray()); var N = new BigInteger(open_key[1].Split(' ').Select(a => byte.Parse(a.ToString(), NumberStyles.HexNumber)).ToArray()); var cryptArr = new BigInteger[bytes.Length / N.ToByteArray().Length + 1]; for (int i = 0, k = 0; i < bytes.Length; i = i) { var data = bytes.Skip(i).Take(N.ToByteArray().Length).ToArray(); cryptArr[k++] = RSAEx.EnCrypt(new BigInteger(data), D, N); i += data.Length; } File.WriteAllLines(RecipientPath + @"\pass.cod", cryptArr.Select(intg => string.Join(" ", intg.ToByteArray().Select(a => a.ToString("X"))))); decryptPassGrid.Visibility = Visibility.Visible; }
private void encryptFile(object sender, RoutedEventArgs e) { var bytes = File.ReadAllBytes(filePathOpen.Text); var open_key = File.ReadAllLines(SenderPath + @"\open_key.txt"); var D = new BigInteger(open_key[0].Split(' ').Select(a => byte.Parse(a.ToString(), NumberStyles.HexNumber)).ToArray()); var N = new BigInteger(open_key[1].Split(' ').Select(a => byte.Parse(a.ToString(), NumberStyles.HexNumber)).ToArray()); var cryptArr = new BigInteger[(bytes.Length / (N.ToByteArray().Length - 1) + 1)]; for (int i = 0, k = 0; i < bytes.Length; i = i) { var data = bytes.Skip(i).Take(N.ToByteArray().Length - 1).ToArray(); cryptArr[k++] = RSAEx.EnCrypt(new BigInteger(data), D, N); i += data.Length; } File.WriteAllLines(filePathEncrypt.Text, cryptArr.Select(intg => string.Join(" ", intg.ToByteArray().Select(a => a.ToString("X"))))); MessageBox.Show("Шифрование завершено"); }