1

i'm having some trouble with this code.

var symmetricKey = new RijndaelManaged { Mode = CipherMode.CBC, IV = iv, KeySize = 128, Key = keyBytes, Padding = PaddingMode.Zeros };

using (var decryptor = symmetricKey.CreateDecryptor())
using (var ms = new MemoryStream(cipherTextBytes))
using (var cs = new CryptoStream(ms, decryptor, CryptoStreamMode.Read))
{
    var plainTextBytes = new byte[cipherTextBytes.Length];
    int decryptedByteCount = cs.Read(plainTextBytes, 0, plainTextBytes.Length);
    return Encoding.UTF8.GetString(plainTextBytes, 0, decryptedByteCount);
}

The problem is here:

var symmetricKey = new RijndaelManaged { Mode = CipherMode.CBC, IV = iv,
                                         KeySize = 128, Key = keyBytes,
                                         Padding = PaddingMode.Zeros };

Because even if i have included the System.Security.Cryptography, it doesn't find the RijndaelManaed. It says:

" Namespace not found. Probably using or assembly reference "

In fact, when i add using System.Security.Cryptography, only options available are:

  • Pkcs
  • X509Certificates
  • Xml

I need to use System.Security.Cryptography.RijndaelManaged

dcastro
  • 66,540
  • 21
  • 145
  • 155
Francesco
  • 23
  • 3

1 Answers1

2

It seems .NET for Windows Store Apps simply does not have System.Security.Cryptography.RijndaelManaged.

The Windows.Security.Cryptography namespace only has one class: CryptographicBuffer.

You'll have to use SymmetricKeyAlgorithmProvider.OpenAlgorithm to choose a symmetric encryption algorithm. Here you'll find a list of all the symmetric algorithms supporter on WinRT.

dcastro
  • 66,540
  • 21
  • 145
  • 155
  • So in this case, how the code transform? I'm at the beginning of C# programming, so i'm not very practiced. I need an AES 128bit Decryptor algorithm – Francesco Mar 21 '14 at 15:41
  • @Francesco See if this question help: [AesManaged Decryption in Metro WinRT application](http://stackoverflow.com/a/11773851/857807). I'm sure you'll find plenty of examples on how to encrypt/decrypt using AES on WinRT. – dcastro Mar 21 '14 at 15:47
  • Sorry man, i was wrong the title of the post. I mean Windows Phone 8, my mistake... Can you help me anyway? – Francesco Mar 21 '14 at 17:56