Objective C的AES 128加密技术交流#Web服务(objective c aes 12

2019-10-17 15:16发布

所以我试图找出如何使这个客观的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;

}

文章来源: objective c aes 128 encryption for a c# web service