# BCrypt

參考資料:(<https://github.com/lustan3216/BlogArticle/wiki/BCrypt-%E5%8A%A0%E5%AF%86%E6%BC%94%E7%AE%97%E6%B3%95%E7%B2%BE%E9%97%A2%E8%A7%A3%E9%87%8B>)

## BCrypt 只能單向加密！ 不能反向解密！

### 應用

那要怎麼在C#中應用呢?

先利用NuGet 下載 BCrypt.Net

並配合下列程式碼

```
using BCryptHelper = BCrypt.Net.BCrypt;

public class Cryptography
{

    public static string Hash(string Text, out string Salt)
    {
        Salt = BCryptHelper.GenerateSalt();
        return BCryptHelper.HashPassword(Text, Salt);
    }
    public static bool VerifyHash(string Text, string HashedText)
    {
        return BCryptHelper.Verify(Text, HashedText);
    }

}
```

方法: 1. 利用亂數加密後的密碼 Hash(要被加密的字串, out 亂數產生的字串)

2\. 密碼是否相符 VerifyHash(輸入的字串，亂數加密後的密碼)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://brianwu.gitbook.io/brian/brians-za-ji/za-ji/mi-ma-xue/bcrypt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
