Can I use WP7 AesManaged to play NIST / FIPS197 (AES128) results?

Simple programmers! I want to allow users of my software to transfer information safely from their Windows Phone devices to several different services in the most convenient, general and platform independent way. Preferably with tools already delivered by Microsoft. For this reason, I looked at the AesManaged class, accessible through the "System.Security.Cryptography" namespace in the Windows Phone 7.1 SDK. However, so far I have not been able to reproduce any NIST example with this class. Among other things, I tried the following:

/* http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf page 35 and 36 */
var passwordBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
var unencryptedBytes = new byte[]{ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };        

using (var aes = new AesManaged())
{
    aes.BlockSize = 128; /* size in bits */
    aes.KeySize = 128; /* size in bits */
    aes.Key = passwordBytes; 

    using (var memoryStream = new MemoryStream())
    {
        using (var cryptoStream = new CryptoStream(memoryStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
        {
            cryptoStream.Write(unencryptedBytes, 0, unencryptedBytes.Length);
            cryptoStream.FlushFinalBlock();

            var stream = memoryStream.ToArray();
            /* 
            should be 
            69-c4-e0-d8-6a-7b-04-30-d8-cd-b7-80-70-b4-c5-5a = 128 bit
            according to http://testprotect.com/appendix/AEScalc and fips-197.pdf
            */
            var output = BitConverter.ToString(stream); 
            /* 
            86-DB-4D-44-72-C0-16-E6-80-B9-D2-B2-3C-6D-00-40-98-4C-59-76-CF-41-DF-4E-A6-46-BB-DE-4C-13-E6-12 
            256 bit? 
            */
        }
    }  
}

(, http://msdn.microsoft.com/de-de/library/system.security.cryptography.aesmanaged.aspx), IV Rfc2898DeriveBytes (, http://msdn.microsoft.com/en-us/library/system.security.cryptography.rfc2898derivebytes.aspx), - , ? "Key Padding" Windows ( https://www.ietf.org/rfc/rfc3394.txt https://www.ietf.org/rfc/rfc5649.txt?). : (CBC http://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged.mode.aspx) Windows Phone?

+3
1

, . , IV-16 , :

/* http://csrc.nist.gov/publications/fips/fips197/fips-197.pdf page 35 and 36 */
var passwordBytes = new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
   0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
var unencryptedBytes = new byte[] { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
   0x77, 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };
var initvectorBytes = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };

using (var aes = new AesManaged())
{
   aes.BlockSize = 128; /* size in bits */
   aes.KeySize = 128; /* size in bits */
   aes.Key = passwordBytes;
   aes.IV = initvectorBytes;

   using (var memoryStream = new MemoryStream())
   {
      using (var cryptoStream = new CryptoStream(
         memoryStream, aes.CreateEncryptor(), CryptoStreamMode.Write))
      {
         cryptoStream.Write(unencryptedBytes, 0, unencryptedBytes.Length);
         cryptoStream.FlushFinalBlock();

         var stream = memoryStream.ToArray();
         /* now you get: 
            69-c4-e0-d8-6a-7b-04-30-d8-cd-b7-80-70-b4-c5-5a = 128 bit
            according to http://testprotect.com/appendix/AEScalc and fips-197.pdf
         */
         var output = BitConverter.ToString(stream);
      }
   }
}

IV - , . AesManaged, AES CBC ( ECB). , - . Padding , . PKCS7 ( ).

+2

All Articles