在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 |
|