c# capta kırma işlemleri için
https://github.com/skotz/captcha-breaking-library
C# kaynak kodları ile projelerinize yardımcı açık source code örnekleri bulun.Programlama ile uraşan coderlara yardımcı olur.
21 Ekim 2016 Cuma
c# ile php arasında şifreli iletişim
Encryption
$iv_to_pass_to_decryption = ''; function encrypt($text, $key) { $iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_256, MCRYPT_MODE_CBC), MCRYPT_RAND); $iv_to_pass_to_decryption = base64_encode($iv); return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv); } |
Decryption
function decrypt($text, $key, $iv) { $text = base64_decode($text); $iv = base64_decode($iv); return mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $text, MCRYPT_MODE_CBC, $iv); } |
C#
Encryption
iv_to_pass_to_decryption = ""; public string encrypt(string text, string key) { byte[] _encdata; MemoryStream ms = new MemoryStream(); RijndaelManaged aes = new RijndaelManaged(); aes.KeySize = 256; aes.BlockSize = 256; aes.Padding = PaddingMode.Zeros; aes.Mode = CipherMode.CBC; aes.GenerateIV(); iv_to_pass_to_decryption = Convert.ToBase64String(aes.IV); ICryptoTransform encryptor = aes.CreateEncryptor(Encoding.Default.GetBytes(key), aes.IV); byte[] _text = Encoding.Default.GetBytes(text); CryptoStream cs = new CryptoStream(ms, encryptor, CryptoStreamMode.Write); cs.Write(_text, 0, _text.Length); cs.FlushFinalBlock(); _encdata = ms.ToArray(); ms.Close(); cs.Close(); return Convert.ToBase64String(_encdata); } |
Decryption
public string decrypt(string text, string key, string iv) { byte[] _data; int i = 0; MemoryStream ms = new MemoryStream(Convert.FromBase64String(text)); RijndaelManaged aes = new RijndaelManaged(); aes.KeySize = 256; aes.BlockSize = 256; aes.Padding = PaddingMode.Zeros; aes.Mode = CipherMode.CBC; ICryptoTransform decryptor = aes.CreateDecryptor( Encoding.Default.GetBytes(key), Convert.FromBase64String(iv)); CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read); _data = new byte[ms.Length]; i = cs.Read(_data, 0, _data.Length); return Encoding.Default.GetString(_data, 0, i); } |
Tip!
c# ile php arasında iletisim
.
C#—-> Send Data —-> PHP Page —-> Processing Data —-> C# Get Information.
Let me Show you the code
Usage Example , C# Code:
1
2
3
4
5
6
7
8
9
10
| using System; class Program { static void Main( string [] args) { string Data = Web.GetPost( "http://www.smart-arab.com/example.php" , "UserName" , "Me" , "Password" , "123" ); Console.WriteLine(Data); } } |
PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| <!--?PHP if (isset( $_POST [ 'UserName' ])) { $UserName = $_POST [ 'UserName' ]; } else { $UserName = null; } if (isset( $_POST [ 'Password' ])) { $Password = $_POST [ 'Password' ]; } else { $Password = null; } echo $UserName . " Is And Password Is " . $Password ?--> |
C# Class : ( You don’t need to go through it deeply, just add it to your Project as a Class file )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
| using System; using System.IO; using System.Net; using System.Text; using System.Windows.Forms; class Web { public static string GetPost( string Url, params string [] postdata) { string result = string .Empty; string data = string .Empty; System.Text.ASCIIEncoding ascii = new ASCIIEncoding(); if (postdata.Length % 2 != 0) { MessageBox.Show( "Parameters must be even , \"user\" , \"value\" , ... etc" , Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); return string .Empty; } for ( int i = 0; i < postdata.Length; i += 2) { data += string .Format( "&{0}={1}" , postdata[i], postdata[i + 1]); } data = data.Remove(0, 1); byte [] bytesarr = ascii.GetBytes(data); try { WebRequest request = WebRequest.Create(Url); request.Method = "POST" ; request.ContentType = "application/x-www-form-urlencoded" ; request.ContentLength = bytesarr.Length; System.IO.Stream streamwriter = request.GetRequestStream(); streamwriter.Write(bytesarr, 0, bytesarr.Length); streamwriter.Close(); WebResponse response = request.GetResponse(); streamwriter = response.GetResponseStream(); System.IO.StreamReader streamread = new System.IO.StreamReader(streamwriter); result = streamread.ReadToEnd(); streamread.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error); } return result; } } |
Happy Posting :)
Kaydol:
Kayıtlar (Atom)