.NET 基础类型全解析
1. 安全字符串处理
在处理安全字符串时, SecureString 不会直接返回其明文内容。若要获取明文,需借助 System.Runtime.InteropServices 命名空间下的 Marshal 类型的相关方法。
' Caractère normal : l’insère dans la chaîne protégée.
If txtPassword.SelectionStart = txtPassword.SelectionLength Then
password.AppendChar(e.KeyChar)
Else
password.InsertAt(txtPassword.SelectionStart, e.KeyChar)
End If
' Affiche (et stocke) un astérisque dans la zone de texte.
e.KeyChar = "*"c
' Convertit le mot de passe en une BSTR non managée.
Dim ptr As IntPtr = Marshal.SecureStringToBSTR(password)
' Pour des questions de démo, convertit la BSTR en une chaîne normale et l’utilise.
Dim pw As String = Marshal.PtrToStringBSTR(ptr)
' Efface la BSTR n
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



