Ejemplo n.º 1
0
        // Token: 0x060001AC RID: 428 RVA: 0x0000654C File Offset: 0x0000474C
        public byte[] Decrypt(byte[] key, byte[] iv, byte[] aad, byte[] cipherText, byte[] authTag)
        {
            IntPtr intPtr = this.OpenAlgorithmProvider(BCrypt.BCRYPT_AES_ALGORITHM, BCrypt.MS_PRIMITIVE_PROVIDER, BCrypt.BCRYPT_CHAIN_MODE_GCM);
            IntPtr hKey;
            IntPtr hglobal = this.ImportKey(intPtr, key, out hKey);

            BCrypt.BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO bcrypt_AUTHENTICATED_CIPHER_MODE_INFO = new BCrypt.BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO(iv, aad, authTag);
            byte[] array2;
            using (bcrypt_AUTHENTICATED_CIPHER_MODE_INFO)
            {
                byte[] array = new byte[this.MaxAuthTagSize(intPtr)];
                int    num   = 0;
                uint   num2  = BCrypt.BCryptDecrypt(hKey, cipherText, cipherText.Length, ref bcrypt_AUTHENTICATED_CIPHER_MODE_INFO, array, array.Length, null, 0, ref num, 0);
                if (num2 != 0U)
                {
                    throw new CryptographicException(string.Format("BCrypt.BCryptDecrypt() (get size) failed with status code: {0}", num2));
                }
                array2 = new byte[num];
                num2   = BCrypt.BCryptDecrypt(hKey, cipherText, cipherText.Length, ref bcrypt_AUTHENTICATED_CIPHER_MODE_INFO, array, array.Length, array2, array2.Length, ref num, 0);
                if (num2 == BCrypt.STATUS_AUTH_TAG_MISMATCH)
                {
                    throw new CryptographicException("BCrypt.BCryptDecrypt(): authentication tag mismatch");
                }
                if (num2 != 0U)
                {
                    throw new CryptographicException(string.Format("BCrypt.BCryptDecrypt() failed with status code:{0}", num2));
                }
            }
            BCrypt.BCryptDestroyKey(hKey);
            Marshal.FreeHGlobal(hglobal);
            BCrypt.BCryptCloseAlgorithmProvider(intPtr, 0U);
            return(array2);
        }
Ejemplo n.º 2
0
 internal static extern uint BCryptDecrypt(IntPtr hKey, byte[] pbInput, int cbInput, ref BCrypt.BCRYPT_AUTHENTICATED_CIPHER_MODE_INFO pPaddingInfo, byte[] pbIV, int cbIV, byte[] pbOutput, int cbOutput, ref int pcbResult, int dwFlags);