> For the complete documentation index, see [llms.txt](https://brianwu.gitbook.io/brian/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://brianwu.gitbook.io/brian/brians-za-ji/za-ji/mi-ma-xue/bcrypt.md).

# 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(輸入的字串，亂數加密後的密碼)
