本文整理汇总了C#中SecureString类的典型用法代码示例。如果您正苦于以下问题:C# SecureString类的具体用法?C# SecureString怎么用?C# SecureString使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SecureString类属于命名空间,在下文中一共展示了SecureString类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateCredential
static SqlCredential CreateCredential(String username)
{
// Prompt the user for a password and construct SqlCredential
SecureString password = new SecureString();
Console.WriteLine("Enter password for " + username + ": ");
ConsoleKeyInfo nextKey = Console.ReadKey(true);
while (nextKey.Key != ConsoleKey.Enter)
{
if (nextKey.Key == ConsoleKey.Backspace)
{
if (password.Length > 0)
{
password.RemoveAt(password.Length - 1);
// erase the last * as well
Console.Write(nextKey.KeyChar);
Console.Write(" ");
Console.Write(nextKey.KeyChar);
}
}
else
{
password.AppendChar(nextKey.KeyChar);
Console.Write("*");
}
nextKey = Console.ReadKey(true);
}
Console.WriteLine();
Console.WriteLine();
password.MakeReadOnly();
return new SqlCredential(username, password);
}
开发者ID:CoraBanff,项目名称:sql-server-samples,代码行数:34,代码来源:Program.cs
示例2: GetPassword
/// <summary>
/// Read a password from the console into a SecureString
/// </summary>
/// <returns>Password stored in a secure string</returns>
public static SecureString GetPassword()
{
SecureString password = new SecureString();
Console.WriteLine("Enter password: ");
// get the first character of the password
ConsoleKeyInfo nextKey = Console.ReadKey(true);
while (nextKey.Key != ConsoleKey.Enter)
{
if (nextKey.Key == ConsoleKey.Backspace)
{
if (password.Length > 0)
{
password.RemoveAt(password.Length - 1);
// erase the last * as well
Console.Write(nextKey.KeyChar);
Console.Write(" ");
Console.Write(nextKey.KeyChar);
}
}
else
{
password.AppendChar(nextKey.KeyChar);
Console.Write("*");
}
nextKey = Console.ReadKey(true);
}
Console.WriteLine();
// lock the password down
password.MakeReadOnly();
return password;
}
开发者ID:repolyo,项目名称:AttendanceLog,代码行数:39,代码来源:index.aspx.cs
示例3: getTokenString
public string getTokenString(string user, SecureString password)
{
//credentials.Add ( new System.Uri ( uri ), "Basic", new NetworkCredential ( boxUser.Text, boxPw.SecurePassword) );
//var url = Path.Combine ( URL, TOKEN );
var client = new HttpClient();
var content = new HttpRequestMessage(HttpMethod.Post, new Uri(URI, TOKEN));
content.Headers()
client.PostAsync(new Uri(URI, TOKEN),);
var request = (HttpWebRequest)HttpWebRequest.Create(new Uri(URI, TOKEN));
request.ContentType = "text/json";
request.Credentials = new NetworkCredential(user, password);
request.Method = "POST";
//var objStream = request.GetRequestStream ();
//var writer = new StreamWriter ( objStream );
//writer.Write ( "{\"comment\":\"ProtonetTool\"}" );
//writer.Flush ();
//writer.Close ();
return ReadResponse(request);
}
开发者ID:Snowyo,项目名称:ProtonetApp,代码行数:25,代码来源:Protonet.cs
示例4: ToSecureString
/// <summary>
/// A String extension method that converts the @this to a secure string.
/// </summary>
/// <param name="this">The @this to act on.</param>
/// <returns>@this as a SecureString.</returns>
public static SecureString ToSecureString(this string @this)
{
var secureString = new SecureString();
foreach (Char c in @this)
secureString.AppendChar(c);
return secureString;
}
开发者ID:fqybzhangji,项目名称:Z.ExtensionMethods,代码行数:13,代码来源:String.ToSecureString.cs
示例5: createSecureString
private static SecureString createSecureString(string s)
{
SecureString result = new SecureString();
foreach(char ch in s)
{
result.AppendChar(ch);
}
return result;
}
开发者ID:externl,项目名称:ice,代码行数:9,代码来源:PasswordCallbackI.cs
示例6: ToSecureString
public static SecureString ToSecureString(string input)
{
SecureString secure = new SecureString();
foreach (char c in input)
{
secure.AppendChar(c);
}
secure.MakeReadOnly();
return secure;
}
开发者ID:hujirong,项目名称:DevOps,代码行数:10,代码来源:DPAPICipher.cs
示例7: ReadPassword
public static SecureString ReadPassword()
{
Console.Write("Password: ");
SecureString secPass = new SecureString();
ConsoleKeyInfo key = Console.ReadKey(true);
while (key.KeyChar != '\r')
{
secPass.AppendChar(key.KeyChar);
key = Console.ReadKey(true);
}
return secPass;
}
开发者ID:Diullei,项目名称:Storm,代码行数:12,代码来源:runas.cs
示例8: X509Certificate
public X509Certificate(byte[] rawData, SecureString password, X509KeyStorageFlags keyStorageFlags)
{
if (rawData == null || rawData.Length == 0)
throw new ArgumentException(SR.Arg_EmptyOrNullArray, nameof(rawData));
ValidateKeyStorageFlags(keyStorageFlags);
using (var safePasswordHandle = new SafePasswordHandle(password))
{
Pal = CertificatePal.FromBlob(rawData, safePasswordHandle, keyStorageFlags);
}
}
开发者ID:crummel,项目名称:dotnet_corefx,代码行数:12,代码来源:X509Certificate.cs
示例9: ToInsecureString
public static string ToInsecureString(SecureString input)
{
string returnValue = string.Empty;
IntPtr ptr = System.Runtime.InteropServices.Marshal.SecureStringToBSTR(input);
try
{
returnValue = System.Runtime.InteropServices.Marshal.PtrToStringBSTR(ptr);
}
finally
{
System.Runtime.InteropServices.Marshal.ZeroFreeBSTR(ptr);
}
return returnValue;
}
开发者ID:hujirong,项目名称:DevOps,代码行数:14,代码来源:DPAPICipher.cs
示例10: ToSecureString
public static SecureString ToSecureString(this IEnumerable<char> input)
{
if (input == null)
{
return null;
}
var secure = new SecureString();
foreach (var c in input)
{
secure.AppendChar(c);
}
secure.MakeReadOnly();
return secure;
}
开发者ID:varunrl,项目名称:SSRSCompanion,代码行数:17,代码来源:SecureIt.cs
示例11: VerifyString
private static void VerifyString(SecureString ss, string exString)
{
IntPtr uniStr = IntPtr.Zero;
try
{
uniStr = SecureStringMarshal.SecureStringToCoTaskMemUnicode(ss);
string acString = Marshal.PtrToStringUni(uniStr);
Assert.Equal(exString.Length, acString.Length);
Assert.Equal(exString, acString);
}
finally
{
if (uniStr != IntPtr.Zero)
SecureStringMarshal.ZeroFreeCoTaskMemUnicode(uniStr);
}
}
开发者ID:nblumhardt,项目名称:corefx,代码行数:17,代码来源:SecureStringTests.cs
示例12: CreateSecureString
private static SecureString CreateSecureString(string exValue)
{
SecureString ss = null;
if (string.IsNullOrEmpty(exValue))
ss = new SecureString();
else
{
unsafe
{
fixed (char* mychars = exValue.ToCharArray())
ss = new SecureString(mychars, exValue.Length);
}
}
Assert.NotNull(ss);
return ss;
}
开发者ID:nblumhardt,项目名称:corefx,代码行数:18,代码来源:SecureStringTests.cs
示例13: GetSshKey
public static ISshKey GetSshKey(this EntrySettings settings,
ProtectedStringDictionary strings, ProtectedBinaryDictionary binaries,
SprContext sprContext)
{
if (!settings.AllowUseOfSshKey) {
return null;
}
KeyFormatter.GetPassphraseCallback getPassphraseCallback =
delegate(string comment)
{
var securePassphrase = new SecureString();
var passphrase = SprEngine.Compile(strings.ReadSafe(
PwDefs.PasswordField), sprContext);
foreach (var c in passphrase) {
securePassphrase.AppendChar(c);
}
return securePassphrase;
};
Func<Stream> getPrivateKeyStream;
Func<Stream> getPublicKeyStream = null;
switch (settings.Location.SelectedType) {
case EntrySettings.LocationType.Attachment:
if (string.IsNullOrWhiteSpace(settings.Location.AttachmentName)) {
throw new NoAttachmentException();
}
var privateKeyData = binaries.Get(settings.Location.AttachmentName);
var publicKeyData = binaries.Get(settings.Location.AttachmentName + ".pub");
getPrivateKeyStream = () => new MemoryStream(privateKeyData.ReadData());
if (publicKeyData != null)
getPublicKeyStream = () => new MemoryStream(publicKeyData.ReadData());
return GetSshKey(getPrivateKeyStream, getPublicKeyStream,
settings.Location.AttachmentName, getPassphraseCallback);
case EntrySettings.LocationType.File:
getPrivateKeyStream = () => File.OpenRead(settings.Location.FileName);
var publicKeyFile = settings.Location.FileName + ".pub";
if (File.Exists(publicKeyFile))
getPublicKeyStream = () => File.OpenRead(publicKeyFile);
return GetSshKey(getPrivateKeyStream, getPublicKeyStream,
settings.Location.AttachmentName, getPassphraseCallback);
default:
return null;
}
}
开发者ID:xenithorb,项目名称:KeeAgent,代码行数:43,代码来源:ExtensionMethods.cs
示例14: SecureStringToCoTaskMemAnsi
public static IntPtr SecureStringToCoTaskMemAnsi(SecureString s) => s != null ? s.MarshalToString(globalAlloc: false, unicode: false) : IntPtr.Zero;
开发者ID:ChuangYang,项目名称:corefx,代码行数:1,代码来源:SecureStringMarshal.CoreCLR.cs
示例15: SecureStringToGlobalAllocUnicode
public static IntPtr SecureStringToGlobalAllocUnicode(SecureString s) => s != null ? s.MarshalToString(globalAlloc: true, unicode: true) : IntPtr.Zero;
开发者ID:ChuangYang,项目名称:corefx,代码行数:1,代码来源:SecureStringMarshal.CoreCLR.cs
示例16: Import
public override void Import (string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
{
byte[] rawData = File.ReadAllBytes (fileName);
Import (rawData, (string)null, keyStorageFlags);
}
开发者ID:nlhepler,项目名称:mono,代码行数:5,代码来源:X509Certificate2.cs
示例17: X509Certificate2
public X509Certificate2 (string fileName, SecureString password, X509KeyStorageFlags keyStorageFlags)
{
Import (fileName, password, keyStorageFlags);
}
开发者ID:nlhepler,项目名称:mono,代码行数:4,代码来源:X509Certificate2.cs
示例18: FindKeePassPassword
public static SecureString FindKeePassPassword(
PwDatabase database,
bool caseSensitive = false,
string username = null,
string url = null,
string title = null,
string notes = null)
{
var entries = FindKeePassEntries(database, caseSensitive, true, username, url, title, notes);
if (entries == null)
return null;
foreach(var entry in entries)
{
var secureString = new SecureString();
var value = entry.Strings.ReadSafe("Password");
foreach (var c in value)
secureString.AppendChar(c);
return secureString;
}
return null;
}
开发者ID:badmishkallc,项目名称:jolt9-devops,代码行数:24,代码来源:Util.cs
示例19: SecureStringToCoTaskMemUnicode
public static IntPtr SecureStringToCoTaskMemUnicode(SecureString s);
开发者ID:ajit2936,项目名称:corefx-progress,代码行数:1,代码来源:System.Security.SecureString.cs
示例20: X509Certificate2
public X509Certificate2 (byte[] rawData, SecureString password) : base (rawData, password)
{
_cert = new MX.X509Certificate (base.GetRawCertData ());
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:4,代码来源:X509CertificateEx.cs
注:本文中的SecureString类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论