本文整理汇总了C#中System.Security.SecureString.ToEncodedClearText方法的典型用法代码示例。如果您正苦于以下问题:C# SecureString.ToEncodedClearText方法的具体用法?C# SecureString.ToEncodedClearText怎么用?C# SecureString.ToEncodedClearText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.SecureString
的用法示例。
在下文中一共展示了SecureString.ToEncodedClearText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHash
/// <summary>
/// Gets the SHA512 of the password.
/// </summary>
/// <param name="password">the password to hash.</param>
/// <param name="hashProvider">The hash provider.</param>
/// <returns>The computed hash.</returns>
private static byte[] GetHash(
SecureString password,
SHA512 hashProvider)
{
byte[] encodedText = password.ToEncodedClearText();
try
{
return hashProvider.ComputeHash(encodedText);
}
finally
{
encodedText.Zero();
}
}
示例2: GetHash
/// <summary>
/// Gets the hash given the account id and secret.
/// </summary>
/// <param name="body">The raw body of the token.</param>
/// <param name="secret">the secret for computing the hash.</param>
/// <returns>the hash value.</returns>
protected static byte[] GetHash(byte[] body, SecureString secret)
{
byte[] key = secret.ToEncodedClearText(Encoding.UTF8);
try
{
using (HMACSHA256 sha = new HMACSHA256(key))
{
return sha.ComputeHash(body);
}
}
finally
{
key.Zero();
}
}
示例3: Protect
/// <summary>
/// Encrypts a secure string with the given certificate.
/// </summary>
/// <param name="userData">the user data to encrypt.</param>
/// <param name="certificate">the certificate for encryption.</param>
/// <returns>the encrypted data.</returns>
public static byte[] Protect(SecureString userData, X509Certificate2 certificate)
{
if (userData == null)
{
throw new ArgumentNullException("userData");
}
if (certificate == null)
{
throw new ArgumentNullException("certificate");
}
byte[] clearText = userData.ToEncodedClearText();
try
{
return Protect(clearText, certificate);
}
finally
{
clearText.Zero();
}
}