大马资讯论坛 - 马来西亚中文资讯平台
标题:
[教学] Xamarin Studio PCLCrypto library AES Encrypt Decrypt
[打印本页]
作者:
资讯王
时间:
2017-2-7 20:47
标题:
[教学] Xamarin Studio PCLCrypto library AES Encrypt Decrypt
在xamarin你可以使用nuget来安装 PCLCrypto
https://github.com/AArnott/PCLCrypto
取代 PHP MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC, System.Security.Cryptography, RijndaelManaged, sample_visual_c_sharp_aes256_imcore_net
public static string EncryptAES(string content, string password)
{
byte[] keyMaterial = Encoding.UTF8.GetBytes(password);
byte[] data = Encoding.UTF8.GetBytes(content);
byte[] iv = new byte[keyMaterial.Length];
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
var key = provider.CreateSymmetricKey(keyMaterial);
byte[] cipherText = WinRTCrypto.CryptographicEngine.Encrypt(key, data, iv);
return Convert.ToBase64String(cipherText);
}
public static string DecryptAES(string content, string password)
{
byte[] keyMaterial = Encoding.UTF8.GetBytes(password);
byte[] data = Convert.FromBase64String(content);
byte[] iv = new byte[keyMaterial.Length];
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
var key = provider.CreateSymmetricKey(keyMaterial);
byte[] cipherText = WinRTCrypto.CryptographicEngine.Decrypt(key, data, iv);
return Encoding.UTF8.GetString(cipherText, 0, cipherText.Length);
}
复制代码
source :
http://stackoverflow.com/questio ... n-windows-phone-8-1
欢迎光临 大马资讯论坛 - 马来西亚中文资讯平台 (http://freeinfo.com.my/)
Powered by Discuz! X3.3