Class Crypto
訊息加解密輔助工具
public class Crypto
- Inheritance
-
Crypto
- Inherited Members
Constructors
Crypto(Encoding)
建構子
public Crypto(Encoding encoding = null)
Parameters
encodingEncoding編碼方式,預設為 ASCII,可自行修改為 UTF8
Properties
CryptoEncoding
加密類別使用的編碼方式,可自行指定為 UTF8 (預設為 ASCII)
public Encoding CryptoEncoding { get; set; }
Property Value
IV
AES 加密初始化向量。預設加密時會自動產生 Base64 格式的 16-byte IV。
public string IV { get; set; }
Property Value
Methods
AESDecryption(string, string)
AES 解密。密文若遭竄改、IV 錯誤或金鑰不同,會丟出 CryptographicException。
public string AESDecryption(string content, string iv)
Parameters
Returns
- string
解密後的內容
AESEncryption(string, string)
AES 加密。使用 AES-CBC 搭配 HMAC-SHA256 驗證密文完整性。
public string AESEncryption(string content, string iv = null)
Parameters
Returns
- string
Base64 格式的加密內容,內含 HMAC 驗證碼
Md5(string)
MD5 雜湊資料
public string Md5(string content = "")
Parameters
contentstring資料
Returns
- string
雜湊後的資料
RandomString(int)
產生指定長度的亂數字串 [A-Za-z0-9]
public string RandomString(int len)
Parameters
lenint指定長度
Returns
- string
亂數字串