09-05-16, 04:30 AM
السلام عليكم ورحمة الله وبركاته
لدي دالة تشفير وفك تشفير فيجوال بيسك دوت نت هل تحويلها الى c sharp كفيل بعملها في xamarin؟
واذا احببت وضع الدالة في كلاس في هذه اللغة فكيف؟
اقصد ماذا اختار من Add new item
التالي ملف الكلاس كله
![[صورة مرفقة: f371a7532f79a01.png]](http://www.m5zn.com/newuploads/2016/05/09/png//f371a7532f79a01.png)
لدي دالة تشفير وفك تشفير فيجوال بيسك دوت نت هل تحويلها الى c sharp كفيل بعملها في xamarin؟
واذا احببت وضع الدالة في كلاس في هذه اللغة فكيف؟
اقصد ماذا اختار من Add new item
PHP كود :
public string Encrypt(string text, string key)
{
try
{
TripleDESCryptoServiceProvider crp = new TripleDESCryptoServiceProvider();
UnicodeEncoding uEncode = new UnicodeEncoding();
byte[] bytPlainText = uEncode.GetBytes(text);
MemoryStream stmCipherText = new MemoryStream();
byte[] slt = {
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
};
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(key, slt);
byte[] bytDerivedKey = pdb.GetBytes(24);
crp.Key = bytDerivedKey;
crp.IV = pdb.GetBytes(8);
CryptoStream csEncrypted = new CryptoStream(stmCipherText, crp.CreateEncryptor(), CryptoStreamMode.Write);
csEncrypted.Write(bytPlainText, 0, bytPlainText.Length);
csEncrypted.FlushFinalBlock();
return Convert.ToBase64String(stmCipherText.ToArray());
}
catch (Exception ex)
{
throw;
}
}
public string Decrypt(string text, string key)
{
TripleDESCryptoServiceProvider crp = default(TripleDESCryptoServiceProvider);
try
{
crp = new TripleDESCryptoServiceProvider();
UnicodeEncoding uEncode = new UnicodeEncoding();
byte[] bytCipherText = Convert.FromBase64String(text);
MemoryStream stmPlainText = new MemoryStream();
MemoryStream stmCipherText = new MemoryStream(bytCipherText);
byte[] slt = {
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
};
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(key, slt);
byte[] bytDerivedKey = pdb.GetBytes(24);
crp.Key = bytDerivedKey;
crp.IV = pdb.GetBytes(8);
CryptoStream csDecrypted = new CryptoStream(stmCipherText, crp.CreateDecryptor(), CryptoStreamMode.Read);
StreamWriter sw = new StreamWriter(stmPlainText);
StreamReader sr = new StreamReader(csDecrypted);
sw.Write(sr.ReadToEnd);
sw.Flush();
csDecrypted.Clear();
crp.Clear();
return uEncode.GetString(stmPlainText.ToArray());
}
catch (Exception ex)
{
throw;
}
}
لقد حولت الدالتين وجربتها بسي شارب(ليس xamarin) نجح التشفير وحدث اخطاء في الفك.
إقتباس :Severity Code Description Project File Line Suppression State
Error CS1503 Argument 1: cannot convert from 'method group' to 'char' Encrypt_test C:\Users\xxx\Desktop\Encrypt_test\txt_encrypt.cs 91 Active
التالي ملف الكلاس كله
PHP كود :
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace Encrypt_test
{
class txt_encrypt
{
//****
public string Encrypt(string text, string key)
{
try
{
TripleDESCryptoServiceProvider crp = new TripleDESCryptoServiceProvider();
UnicodeEncoding uEncode = new UnicodeEncoding();
byte[] bytPlainText = uEncode.GetBytes(text);
MemoryStream stmCipherText = new MemoryStream();
byte[] slt = {
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
};
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(key, slt);
byte[] bytDerivedKey = pdb.GetBytes(24);
crp.Key = bytDerivedKey;
crp.IV = pdb.GetBytes(8);
CryptoStream csEncrypted = new CryptoStream(stmCipherText, crp.CreateEncryptor(), CryptoStreamMode.Write);
csEncrypted.Write(bytPlainText, 0, bytPlainText.Length);
csEncrypted.FlushFinalBlock();
return Convert.ToBase64String(stmCipherText.ToArray());
}
catch (Exception ex)
{
throw;
}
}
public string Decrypt(string text, string key)
{
TripleDESCryptoServiceProvider crp = default(TripleDESCryptoServiceProvider);
try
{
crp = new TripleDESCryptoServiceProvider();
UnicodeEncoding uEncode = new UnicodeEncoding();
byte[] bytCipherText = Convert.FromBase64String(text);
MemoryStream stmPlainText = new MemoryStream();
MemoryStream stmCipherText = new MemoryStream(bytCipherText);
byte[] slt = {
0,
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11,
12
};
Rfc2898DeriveBytes pdb = new Rfc2898DeriveBytes(key, slt);
byte[] bytDerivedKey = pdb.GetBytes(24);
crp.Key = bytDerivedKey;
crp.IV = pdb.GetBytes(8);
CryptoStream csDecrypted = new CryptoStream(stmCipherText, crp.CreateDecryptor(), CryptoStreamMode.Read);
StreamWriter sw = new StreamWriter(stmPlainText);
StreamReader sr = new StreamReader(csDecrypted);
sw.Write(sr.ReadToEnd);
sw.Flush();
csDecrypted.Clear();
crp.Clear();
return uEncode.GetString(stmPlainText.ToArray());
}
catch (Exception ex)
{
throw;
}
}
//***\\\
}
}
![[صورة مرفقة: f371a7532f79a01.png]](http://www.m5zn.com/newuploads/2016/05/09/png//f371a7532f79a01.png)
![[صورة مرفقة: ConceptualArchitecture.png]](https://developer.xamarin.com/guides/cross-platform/application_fundamentals/building_cross_platform_applications/part_3_-_setting_up_a_xamarin_cross_platform_solution/Images/ConceptualArchitecture.png)


![[صورة مرفقة: 4platforms12.jpg]](http://www.xlsoft.com/en/products/xamarin/images/4platforms12.jpg)
![[صورة مرفقة: Behaviors.png]](https://blog.xamarin.com/wp-content/uploads/2015/02/Behaviors.png)
![[صورة مرفقة: introduction-to-xamarinforms-2-638.jpg?cb=1402662898]](http://image.slidesharecdn.com/introductiontoxamarin-140610171350-phpapp02/95/introduction-to-xamarinforms-2-638.jpg?cb=1402662898)