Advertisement
andrzejiwaniuk

[Napisz sam] Program do szyfrowania tekstu

Jun 13th, 2013
1,583
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. using System.Security.Cryptography;
  16. using System.Diagnostics;
  17.  
  18.  
  19. namespace SzyfrowanieMD5_csharp
  20. {
  21.    
  22.     public partial class MainWindow : Window
  23.     {
  24.         public MainWindow()
  25.         {
  26.             InitializeComponent();
  27.              
  28.                  
  29.         }
  30.  
  31.         private void Button_Click(object sender, RoutedEventArgs e)
  32.         {
  33.             txtBlock.Text = MD5(txtBox.Text);
  34.         }
  35.  
  36.         private string MD5(string Value)
  37.         {
  38.             System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
  39.             byte[] data = System.Text.Encoding.ASCII.GetBytes(Value);
  40.             data = x.ComputeHash(data);
  41.             string ret = "";
  42.             for (int i = 0; i < data.Length; i++)
  43.                 ret += data[i].ToString("x2").ToLower();
  44.             return ret;
  45.         }
  46.        
  47.         public static string sha1encrypt(string phrase)
  48.         {
  49.             UTF8Encoding encoder = new UTF8Encoding();
  50.             SHA1CryptoServiceProvider sha1hasher = new SHA1CryptoServiceProvider();
  51.             byte[] hashedDataBytes = sha1hasher.ComputeHash(encoder.GetBytes(phrase));
  52.             return byteArrayToString(hashedDataBytes);
  53.         }
  54.  
  55.         public static string sha256encrypt(string phrase)
  56.         {
  57.             UTF8Encoding encoder = new UTF8Encoding();
  58.             SHA256Managed sha256hasher = new SHA256Managed();
  59.             byte[] hashedDataBytes = sha256hasher.ComputeHash(encoder.GetBytes(phrase));
  60.             return byteArrayToString(hashedDataBytes);
  61.         }
  62.         public static string sha384encrypt(string phrase)
  63.         {
  64.             UTF8Encoding encoder = new UTF8Encoding();
  65.             SHA384Managed sha384hasher = new SHA384Managed();
  66.             byte[] hashedDataBytes = sha384hasher.ComputeHash(encoder.GetBytes(phrase));
  67.             return byteArrayToString(hashedDataBytes);
  68.         }
  69.         public static string sha512encrypt(string phrase)
  70.         {
  71.             UTF8Encoding encoder = new UTF8Encoding();
  72.             SHA512Managed sha512hasher = new SHA512Managed();
  73.             byte[] hashedDataBytes = sha512hasher.ComputeHash(encoder.GetBytes(phrase));
  74.             return byteArrayToString(hashedDataBytes);
  75.         }
  76.         public static string byteArrayToString(byte[] inputArray)
  77.         {
  78.             StringBuilder output = new StringBuilder("");
  79.             for (int i = 0; i < inputArray.Length; i++)
  80.             {
  81.                 output.Append(inputArray[i].ToString("X2"));
  82.             }
  83.             return output.ToString();
  84.         }
  85.  
  86.         private void Button_Click_1(object sender, RoutedEventArgs e)
  87.         {
  88.             txtBlock.Text = sha256encrypt(txtBox.Text);
  89.         }
  90.  
  91.         private void Button_Click_2(object sender, RoutedEventArgs e)
  92.         {
  93.             Process.Start("chrome.exe");
  94.         }
  95.  
  96.    
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement