Skip to main content

Microsoft Silverlight

Answered Question Working around crypto restrictions in Silverlight 2 or 3RSS Feed

(0)

aronchick
aronchick

Member

Member

0 points

3 Posts

Working around crypto restrictions in Silverlight 2 or 3

I'm doing some work with a server side service I don't control. The following works fine in standard C#, but fails to compile (due to missing crypto classes) in Silverlight 2 and 3.

    static String DecryptString()
   
{
        s
= "<cipherTextHere>";

       
byte[] toDecryptArray = Convert.FromBase64String(s);
       
string key = "<key here>";

       
byte[] keyArray = new byte[key.Length / 2];
       
for (int i = 0; i < keyArray.Length; i++)
       
{
            keyArray
[i] = Convert.ToByte(Convert.ToInt32(key.Substring(i * 2, 2), 16));
       
}

       
using (var algo = new System.Security.Cryptography.AesManaged())
       
{

            algo
.Padding = PaddingMode.PKCS7;
            algo
.Mode = CipherMode.ECB;

            algo
.Key = keyArray;

           
ICryptoTransform cTransform = algo.CreateDecryptor();
           
byte[] resultArray = cTransform.TransformFinalBlock(
                                 toDecryptArray
, 0, toDecryptArray.Length);

           
return (UTF8Encoding.UTF8.GetString(resultArray, 0, resultArray.Length));

       
}
   
}

What are my options?

 

jackbond
jackbond

Contributor

Contributor

2820 points

725 Posts

Re: Working around crypto restrictions in Silverlight 2 or 3

Which crypto classes are missing? System.Security.Cryptography.AesManaged is in there.

clint1222
clint1222

Participant

Participant

1542 points

216 Posts

Answered Question

Re: Working around crypto restrictions in Silverlight 2 or 3

The SymmetricAlgorithm.Padding and SymmetricAlgorithm.Mode aren't available in Silverlight 2.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities