internal static byte[] AESKeyWrapDecrypt(byte[] rgbKey, byte[] rgbEncryptedWrappedKeyData)
 {
     int num = (rgbEncryptedWrappedKeyData.Length >> 3) - 1;
     if (((rgbEncryptedWrappedKeyData.Length % 8) != 0) || (num <= 0))
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_KW_BadKeySize"));
     }
     byte[] dst = new byte[num << 3];
     ICryptoTransform transform = new RijndaelManaged { Key = rgbKey, Mode = CipherMode.ECB, Padding = PaddingMode.None }.CreateDecryptor();
     if (num == 1)
     {
         byte[] src = transform.TransformFinalBlock(rgbEncryptedWrappedKeyData, 0, rgbEncryptedWrappedKeyData.Length);
         for (int k = 0; k < 8; k++)
         {
             if (src[k] != s_rgbAES_KW_IV[k])
             {
                 throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_BadWrappedKeySize"));
             }
         }
         Buffer.BlockCopy(src, 8, dst, 0, 8);
         return dst;
     }
     long num3 = 0L;
     Buffer.BlockCopy(rgbEncryptedWrappedKeyData, 8, dst, 0, dst.Length);
     byte[] buffer3 = new byte[8];
     byte[] buffer4 = new byte[0x10];
     Buffer.BlockCopy(rgbEncryptedWrappedKeyData, 0, buffer3, 0, 8);
     for (int i = 5; i >= 0; i--)
     {
         for (int m = num; m >= 1; m--)
         {
             num3 = m + (i * num);
             for (int n = 0; n < 8; n++)
             {
                 byte num7 = (byte) ((num3 >> (8 * (7 - n))) & 0xffL);
                 buffer3[n] = (byte) (buffer3[n] ^ num7);
             }
             Buffer.BlockCopy(buffer3, 0, buffer4, 0, 8);
             Buffer.BlockCopy(dst, 8 * (m - 1), buffer4, 8, 8);
             byte[] buffer5 = transform.TransformFinalBlock(buffer4, 0, 0x10);
             Buffer.BlockCopy(buffer5, 8, dst, 8 * (m - 1), 8);
             Buffer.BlockCopy(buffer5, 0, buffer3, 0, 8);
         }
     }
     for (int j = 0; j < 8; j++)
     {
         if (buffer3[j] != s_rgbAES_KW_IV[j])
         {
             throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_BadWrappedKeySize"));
         }
     }
     return dst;
 }
コード例 #2
0
ファイル: EncodeHelper.cs プロジェクト: windygu/asxinyunet
 public static string AES_Encrypt(string encryptString, string encryptKey)
 {
     encryptKey = smethod_0(encryptKey, 0x20, "");
     encryptKey = encryptKey.PadRight(0x20, ' ');
     ICryptoTransform transform = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 0x20)), IV = byte_0 }.CreateEncryptor();
     byte[] bytes = Encoding.UTF8.GetBytes(encryptString);
     return Convert.ToBase64String(transform.TransformFinalBlock(bytes, 0, bytes.Length));
 }
コード例 #3
0
ファイル: EncodeHelper.cs プロジェクト: windygu/asxinyunet
 public static string AES_Decrypt(string decryptString, string decryptKey)
 {
     try
     {
         decryptKey = smethod_0(decryptKey, 0x20, "");
         decryptKey = decryptKey.PadRight(0x20, ' ');
         ICryptoTransform transform = new RijndaelManaged { Key = Encoding.UTF8.GetBytes(decryptKey), IV = byte_0 }.CreateDecryptor();
         byte[] inputBuffer = Convert.FromBase64String(decryptString);
         byte[] bytes = transform.TransformFinalBlock(inputBuffer, 0, inputBuffer.Length);
         return Encoding.UTF8.GetString(bytes);
     }
     catch
     {
         return string.Empty;
     }
 }
 internal static byte[] AESKeyWrapEncrypt(byte[] rgbKey, byte[] rgbWrappedKeyData)
 {
     int num = rgbWrappedKeyData.Length >> 3;
     if (((rgbWrappedKeyData.Length % 8) != 0) || (num <= 0))
     {
         throw new CryptographicException(SecurityResources.GetResourceString("Cryptography_Xml_KW_BadKeySize"));
     }
     ICryptoTransform transform = new RijndaelManaged { Key = rgbKey, Mode = CipherMode.ECB, Padding = PaddingMode.None }.CreateEncryptor();
     if (num == 1)
     {
         byte[] buffer = new byte[s_rgbAES_KW_IV.Length + rgbWrappedKeyData.Length];
         Buffer.BlockCopy(s_rgbAES_KW_IV, 0, buffer, 0, s_rgbAES_KW_IV.Length);
         Buffer.BlockCopy(rgbWrappedKeyData, 0, buffer, s_rgbAES_KW_IV.Length, rgbWrappedKeyData.Length);
         return transform.TransformFinalBlock(buffer, 0, buffer.Length);
     }
     long num2 = 0L;
     byte[] dst = new byte[(num + 1) << 3];
     Buffer.BlockCopy(rgbWrappedKeyData, 0, dst, 8, rgbWrappedKeyData.Length);
     byte[] buffer3 = new byte[8];
     byte[] buffer4 = new byte[0x10];
     Buffer.BlockCopy(s_rgbAES_KW_IV, 0, buffer3, 0, 8);
     for (int i = 0; i <= 5; i++)
     {
         for (int j = 1; j <= num; j++)
         {
             num2 = j + (i * num);
             Buffer.BlockCopy(buffer3, 0, buffer4, 0, 8);
             Buffer.BlockCopy(dst, 8 * j, buffer4, 8, 8);
             byte[] src = transform.TransformFinalBlock(buffer4, 0, 0x10);
             for (int k = 0; k < 8; k++)
             {
                 byte num6 = (byte) ((num2 >> (8 * (7 - k))) & 0xffL);
                 buffer3[k] = (byte) (num6 ^ src[k]);
             }
             Buffer.BlockCopy(src, 8, dst, 8 * j, 8);
         }
     }
     Buffer.BlockCopy(buffer3, 0, dst, 0, 8);
     return dst;
 }