本文整理汇总了VB.NET中System.Runtime.InteropServices.Marshal.SecureStringToCoTaskMemAnsi方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Marshal.SecureStringToCoTaskMemAnsi方法的具体用法?VB.NET Marshal.SecureStringToCoTaskMemAnsi怎么用?VB.NET Marshal.SecureStringToCoTaskMemAnsi使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Runtime.InteropServices.Marshal
的用法示例。
在下文中一共展示了Marshal.SecureStringToCoTaskMemAnsi方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Runtime.InteropServices
Imports System.Security
Module Example
Sub Main()
Dim unmanagedRef As IntPtr
' Ask the user for a password.
Console.Write("Please enter your password: ")
Dim passWord As SecureString = GetPassword()
Console.WriteLine("Copying and decrypting the string to unmanaged memory...")
' Copy the Secure string to unmanaged memory (and decrypt it).
unmanagedRef = Marshal.SecureStringToCoTaskMemAnsi(passWord)
If unmanagedRef <> IntPtr.Size Then
Console.WriteLine("Zeroing out unmanaged memory...")
Marshal.ZeroFreeCoTaskMemAnsi(unmanagedRef)
End If
passWord.Dispose()
Console.WriteLine("Done.")
End Sub
Function GetPassword() As SecureString
Dim password As New SecureString()
' get the first character of the password
Dim nextKey As ConsoleKeyInfo = Console.ReadKey(True)
While nextKey.Key <> ConsoleKey.Enter
If nextKey.Key = ConsoleKey.BackSpace Then
If password.Length > 0 Then
password.RemoveAt(password.Length - 1)
' erase the last * as well
Console.Write(nextKey.KeyChar)
Console.Write(" ")
Console.Write(nextKey.KeyChar)
End If
Else
password.AppendChar(nextKey.KeyChar)
Console.Write("*")
End If
nextKey = Console.ReadKey(True)
End While
Console.WriteLine()
' lock the password down
password.MakeReadOnly()
Return password
End Function
End Module
开发者ID:VB.NET开发者,项目名称:System.Runtime.InteropServices,代码行数:60,代码来源:Marshal.SecureStringToCoTaskMemAnsi