So I finally found something a little more understable in implementing a AES 128 encryption for a .Net Wcf Service with the same encryption. My problem with it now is that whenever it would try to decrypt the string it would have a step where it does a FromBase64String convert which will give me an error:
static public string DecryptString(string message, string key)
{
string output = "";
Rijndael aes = new RijndaelManaged();
try
{
byte[] encrypted = Convert.FromBase64String(message);
byte[] cipherText = GetCipherText(encrypted);
aes.Key = Convert.FromBase64String(key);
aes.Mode = CipherMode.CBC;
aes.IV = GetIV(encrypted);
using (MemoryStream ms = new MemoryStream())
{
using (ICryptoTransform decryptor = aes.CreateDecryptor())
{
using (CryptoStream cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Write))
{
cs.Write(cipherText, 0, cipherText.Length);
cs.FlushFinalBlock();
byte[] decrypted = ms.ToArray();
output = Encoding.UTF8.GetString(decrypted);
}
}
}
}
The error is:
Index was outside the bounds of the array.
and it happens on the
cs.FlushFinalBlock();
This is the encryption that it produced for the message "heythere" and a key of "25f9e794323b453885f5181f1b624d0b"
0suql40BUGiDoFA4SdXJAA==
This is coming from my .Net encryption:
unNWQfm9RaU/HgKlDNEmoXZaTzsuBoTNsA2UvDKZhc4=
PS For the iPhone encryption of AES 128, this is where I got the codes from: