示例#1
0
        private byte[] GetProperty(IntPtr hAlg, string name)
        {
            var size   = 0;
            var status = BCrypt.BCryptGetProperty(hAlg, name, null, 0, ref size, 0x0);

            if (status != BCrypt.ERROR_SUCCESS)
            {
                throw new CryptographicException(
                          $"BCrypt.BCryptGetProperty() (get size) failed with status code:{status}");
            }

            var value = new byte[size];

            status = BCrypt.BCryptGetProperty(hAlg, name, value, value.Length, ref size, 0x0);

            if (status != BCrypt.ERROR_SUCCESS)
            {
                throw new CryptographicException($"BCrypt.BCryptGetProperty() failed with status code:{status}");
            }

            return(value);
        }
示例#2
0
        private IntPtr OpenAlgorithmProvider(string alg, string provider, string chainingMode)
        {
            var status = BCrypt.BCryptOpenAlgorithmProvider(out var hAlg, alg, provider, 0x0);

            if (status != BCrypt.ERROR_SUCCESS)
            {
                throw new CryptographicException(
                          $"BCrypt.BCryptOpenAlgorithmProvider() failed with status code:{status}");
            }

            var chainMode = Encoding.Unicode.GetBytes(chainingMode);

            status = BCrypt.BCryptSetAlgorithmProperty(hAlg, BCrypt.BCRYPT_CHAINING_MODE, chainMode, chainMode.Length,
                                                       0x0);

            if (status != BCrypt.ERROR_SUCCESS)
            {
                throw new CryptographicException(
                          $"BCrypt.BCryptSetAlgorithmProperty(BCrypt.BCRYPT_CHAINING_MODE, BCrypt.BCRYPT_CHAIN_MODE_GCM) failed with status code:{status}");
            }

            return(hAlg);
        }