public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV)
        {
            if (keySize < 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
            }
            int num = X509Utils.NameOrOidToAlgId(alghashname, OidGroup.HashAlgorithm);

            if (num == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }
            int num2 = X509Utils.NameOrOidToAlgId(algname, OidGroup.AllGroups);

            if (num2 == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }
            if (rgbIV == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidIV"));
            }
            byte[] result = null;
            PasswordDeriveBytes.DeriveKey(this.ProvHandle, num2, num, this._password, this._password.Length, keySize << 16, rgbIV, rgbIV.Length, JitHelpers.GetObjectHandleOnStack <byte[]>(ref result));
            return(result);
        }
Ejemplo n.º 2
0
        public byte[] CryptDeriveKey(string algname, string alghashname, int keySize, byte[] rgbIV)
        {
            if (keySize < 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_InvalidKeySize"));
            }
            int algId1 = X509Utils.NameOrOidToAlgId(alghashname, OidGroup.HashAlgorithm);

            if (algId1 == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }
            int algId2 = X509Utils.NameOrOidToAlgId(algname, OidGroup.AllGroups);

            if (algId2 == 0)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidAlgorithm"));
            }
            if (rgbIV == null)
            {
                throw new CryptographicException(Environment.GetResourceString("Cryptography_PasswordDerivedBytes_InvalidIV"));
            }
            byte[]         o          = (byte[])null;
            SafeProvHandle provHandle = this.ProvHandle;
            int            algid      = algId2;
            int            algidHash  = algId1;

            byte[] password = this._password;
            int    length1  = this._password.Length;
            int    dwFlags  = keySize << 16;

            byte[] IV      = rgbIV;
            int    length2 = IV.Length;
            ObjectHandleOnStack objectHandleOnStack = JitHelpers.GetObjectHandleOnStack <byte[]>(ref o);

            PasswordDeriveBytes.DeriveKey(provHandle, algid, algidHash, password, length1, dwFlags, IV, length2, objectHandleOnStack);
            return(o);
        }