所以我试图弄清楚如何制作一个客观的 c 版本,因为它是已实现的 wcf 服务安全性的一部分。我的主要问题是 Idk 从哪里开始,因为一些文章/教程会在开头自动填充 0(不确定这是否是他们的 IV),如下所示:
(几个回复下来)
http://iphonedevsdk.com/forum/iphone-sdk-development/60926-aesencryption-in-objective-c-and-php.html
与不使用任何填充的此相比:
Objective-C 解密 AES 128 cbc 十六进制字符串
无论如何,这就是 wcf 使用 AES 128 加密的方式。非常感谢任何建议或推动正确方向的方法。谢谢!!!。
public class EncryptionAES128
{
static public string EncryptString(string inputString, string key)
{
string output = "";
Rijndael encryption = new RijndaelManaged();
try
{
encryption.IV = GenerateIV();
encryption.Key = StringToByte(key);
ICryptoTransform encryptor = encryption.CreateEncryptor(encryption.Key, encryption.IV);
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
swEncrypt.Write(inputString);
}
byte[] cipherText = msEncrypt.ToArray();
byte[] encrypted = new byte[cipherText.Length + encryption.IV.Length];
encryption.IV.CopyTo(encrypted, 0);
cipherText.CopyTo(encrypted, IV_LENGTH);
output = ByteToString(encrypted);
}
}
}
catch (Exception ex)
{
throw ex;
}
return output;
}