加密字符串AES Windows Phone 8.1 [英] Encrypt String AES Windows Phone 8.1
问题描述
我是AES加密的新功能。
我必须在服务器上运行的代码进行加密。
public static string Encrypt(string text,byte [] key,byte [] iv,int keysize = 128,int blocksize = 128,CipherMode cipher = CipherMode.CBC,PaddingMode padding = PaddingMode.PKCS7)
{
AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
aes.BlockSize = blocksize;
aes.KeySize = keysize;
aes.Mode = cipher;
aes.Padding = padding;
byte [] src = Encoding.UTF8.GetBytes(text);
using(ICryptoTransform encrypt = aes.CreateEncryptor(key,iv))
{
byte [] dest = encrypt.TransformFinalBlock(src,0,src.Length);
encrypt.Dispose();
return Convert.ToBase64String(dest);
}
}
我已经有了这个,有一个图书馆Bouncy Castle,但是我似乎找不到一个简单的例子。
byte [] key = Encoding.UTF8.GetBytes([SECRETKEY ]);
byte [] iv = Encoding.UTF8.GetBytes([IV]);
var cipher = CipherUtilities.GetCipher(AES / CBC / PKCS7Padding);
cipher.Init(true,new KeyParameter(key));
如果可以帮助我也有运行Android客户端的代码。
让我知道,然后我可以发表。
你可以使用PCLCrypto库,有一个nuget包可用(Install-Package PclCrypto)
从 https://github.com/AArnott/PCLCrypto/wiki/Crypto-Recipes :
执行AES加密/解密
byte [] keyMaterial;
byte [] data;
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
var key = provider.CreateSymmetricKey(keyMaterial);
byte [] iv = null; //这是可选的,但加密和解密两者必须相同。
byte [] cipherText = WinRTCrypto.CryptographicEngine.Encrypt(key,data,iv);
byte [] plainText = WinRTCrypto.CryptographicEngine.Decrypt(key,cipherText,iv);
cipherText变量是加密数据,plainText是再次解密的加密变量
I'm making an app which will need to encrypt a string. I'm completely new to AES encryption.
I have to code that runs on the server to encrypt.
public static string Encrypt(string text, byte[] key, byte[] iv, int keysize = 128, int blocksize = 128, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7)
{
AesCryptoServiceProvider aes = new AesCryptoServiceProvider();
aes.BlockSize = blocksize;
aes.KeySize = keysize;
aes.Mode = cipher;
aes.Padding = padding;
byte[] src = Encoding.UTF8.GetBytes(text);
using (ICryptoTransform encrypt = aes.CreateEncryptor(key, iv))
{
byte[] dest = encrypt.TransformFinalBlock(src, 0, src.Length);
encrypt.Dispose();
return Convert.ToBase64String(dest);
}
}
I already have this, with a library Bouncy Castle, but I can't seem to find a simple example.
byte[] key = Encoding.UTF8.GetBytes("[SECRETKEY]");
byte[] iv = Encoding.UTF8.GetBytes("[IV]");
var cipher = CipherUtilities.GetCipher("AES/CBC/PKCS7Padding");
cipher.Init(true, new KeyParameter(key));
If it can help I also have the code which runs an Android client. Let me know then I can post it.
You can use the PCLCrypto library, there's a nuget package available (Install-Package PclCrypto)
From https://github.com/AArnott/PCLCrypto/wiki/Crypto-Recipes:
Perform AES encryption/decryption
byte[] keyMaterial;
byte[] data;
var provider = WinRTCrypto.SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithm.AesCbcPkcs7);
var key = provider.CreateSymmetricKey(keyMaterial);
byte[] iv = null; // this is optional, but must be the same for both encrypting and decrypting
byte[] cipherText = WinRTCrypto.CryptographicEngine.Encrypt(key, data, iv);
byte[] plainText = WinRTCrypto.CryptographicEngine.Decrypt(key, cipherText, iv);
The cipherText variable is the encrypted data, plainText is the encrypted variable decrypted again
这篇关于加密字符串AES Windows Phone 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!