本文整理汇总了C#中System.Security.Cryptography.SHA256Managed.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# SHA256Managed.Clear方法的具体用法?C# SHA256Managed.Clear怎么用?C# SHA256Managed.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA256Managed
的用法示例。
在下文中一共展示了SHA256Managed.Clear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SettingsProvider
static SettingsProvider()
{
//read settings from configuration
var useHashingString = ConfigurationManager.AppSettings["UseHashingForEncryption"];
bool useHashing = true;
if (string.Compare( useHashingString, "false", true ) == 0)
{
useHashing = false;
}
_encryptionPrefix = ConfigurationManager.AppSettings["EncryptionPrefix"];
if (string.IsNullOrEmpty( _encryptionPrefix ))
{
_encryptionPrefix = "encryptedHidden_";
}
_saltGeneratorKey = ConfigurationManager.AppSettings["EncryptionSaltGeneratorKey"];
if (string.IsNullOrEmpty( _saltGeneratorKey ))
{
_saltGeneratorKey = "encryptionSaltKey";
}
var key = ConfigurationManager.AppSettings["EncryptionKey"];
if (useHashing)
{
var hash = new SHA256Managed();
_encryptionKey = hash.ComputeHash( UTF8Encoding.UTF8.GetBytes( key ) );
hash.Clear();
//hash.Dispose();
}
else
{
_encryptionKey = UTF8Encoding.UTF8.GetBytes( key );
}
}
示例2: EncryptSettingsProvider
public EncryptSettingsProvider()
{
//read settings from configuration
var useHashingString = ConfigurationManager.AppSettings["UseHashingForEncryption"];
var useHashing = System.String.Compare(useHashingString, "false", System.StringComparison.OrdinalIgnoreCase) != 0;
_encryptionPrefix = ConfigurationManager.AppSettings["EncryptionPrefix"];
if (string.IsNullOrWhiteSpace(_encryptionPrefix))
{
_encryptionPrefix = "encryptedHidden_";
}
var key = ConfigurationManager.AppSettings["EncryptionKey"];
if (useHashing)
{
var hash = new SHA256Managed();
_encryptionKey = hash.ComputeHash(Encoding.UTF8.GetBytes(key));
hash.Clear();
hash.Dispose();
}
else
{
_encryptionKey = Encoding.UTF8.GetBytes(key);
}
}
示例3: Encrypt
public string Encrypt(string content)
{
SHA256Managed hasher = new SHA256Managed();
byte[] textWithSaltBytes = Encoding.UTF8.GetBytes(string.Concat(content, "ultraSafeSalt"));
byte[] hashedBytes = hasher.ComputeHash(textWithSaltBytes);
hasher.Clear();
return Convert.ToBase64String(hashedBytes);
}
示例4: SHA256Encrypt
/// <summary>
/// SHA256加密
/// </summary>
/// <param name="insertStr"></param>
/// <returns></returns>
public static string SHA256Encrypt(string insertStr)
{
byte[] tmpByte;
SHA256 sha256 = new SHA256Managed();
tmpByte = sha256.ComputeHash(GetKeyByteArray(insertStr));
sha256.Clear();
return GetStringValue(tmpByte);
}
示例5: SHA256Encrypt
/// <summary>
/// SHA256 散列算法加密
/// </summary>
/// <param name="data">要加密的内容</param>
/// <returns></returns>
public static string SHA256Encrypt(string data)
{
using (var sha256 = new SHA256Managed())
{
byte[] buffer = Encoding.UTF8.GetBytes(data);
byte[] sha256Data = sha256.ComputeHash(buffer);
sha256.Clear();
return BitConverter.ToString(sha256Data).Replace("-", "").ToLower();
}
}
示例6: CreateStringHash
public static string CreateStringHash(string unHashedString)
{
var encodedUnHashedString = Encoding.Unicode.GetBytes(unHashedString);
var hashingObj = new SHA256Managed();
var hashCode = hashingObj.ComputeHash(encodedUnHashedString);
var hashBase64 = Convert.ToBase64String(hashCode);
var stringWithHash = unHashedString + hashBase64;
hashingObj.Clear();
return (stringWithHash);
}
示例7: FromString
public static string FromString(string input, HashType hashtype)
{
Byte[] clearBytes;
Byte[] hashedBytes;
string output = String.Empty;
switch (hashtype)
{
case HashType.RIPEMD160:
clearBytes = new UTF8Encoding().GetBytes(input);
RIPEMD160 myRIPEMD160 = RIPEMD160Managed.Create();
hashedBytes = myRIPEMD160.ComputeHash(clearBytes);
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.MD5:
clearBytes = new UTF8Encoding().GetBytes(input);
hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.SHA1:
clearBytes = Encoding.UTF8.GetBytes(input);
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
sha1.ComputeHash(clearBytes);
hashedBytes = sha1.Hash;
sha1.Clear();
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.SHA256:
clearBytes = Encoding.UTF8.GetBytes(input);
SHA256 sha256 = new SHA256Managed();
sha256.ComputeHash(clearBytes);
hashedBytes = sha256.Hash;
sha256.Clear();
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.SHA384:
clearBytes = Encoding.UTF8.GetBytes(input);
SHA384 sha384 = new SHA384Managed();
sha384.ComputeHash(clearBytes);
hashedBytes = sha384.Hash;
sha384.Clear();
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
case HashType.SHA512:
clearBytes = Encoding.UTF8.GetBytes(input);
SHA512 sha512 = new SHA512Managed();
sha512.ComputeHash(clearBytes);
hashedBytes = sha512.Hash;
sha512.Clear();
output = BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
break;
}
return output;
}
示例8: GenerateSha2PasswordHash
public static string GenerateSha2PasswordHash(string userId, string password, string credentialSalt)
{
if (userId == null || password == null || userId.Contains(Separator) || password.Contains(Separator))
return null;
var hashTool = new SHA256Managed();
var saltedInput = userId + Separator + password + Separator + credentialSalt;
var saltedBytes = Encoding.UTF8.GetBytes(saltedInput);
var encryptedBytes = hashTool.ComputeHash(saltedBytes);
hashTool.Clear();
var output = Convert.ToBase64String(encryptedBytes);
return output;
}
示例9: Encriptar
public static byte[] Encriptar(string strPassword, string strSalt, int intIteraciones)
{
string _strPasswordSalt = strPassword + strSalt;
SHA256Managed _objSha256 = new SHA256Managed();
byte[] _objTemporal = null;
try
{
_objTemporal = System.Text.Encoding.UTF8.GetBytes(_strPasswordSalt);
for (int i = 0; i <= intIteraciones - 1; i++)
_objTemporal = _objSha256.ComputeHash(_objTemporal);
}
finally { _objSha256.Clear(); }
return _objTemporal;
}
示例10: Crypto
public Crypto(bool useSalt)
{
if (!Initialized)
{
Initialized = true;
string strKeyPhrase = @"Apple*Crisp7";
byte[] byteKeyPhrase = Encoding.ASCII.GetBytes(strKeyPhrase);
SHA256Managed sha256 = new SHA256Managed();
sha256.ComputeHash(byteKeyPhrase);
Key = new byte[24];
for (int i = 0; i < 24; i++)
Key[i] = sha256.Hash[i];
string strIVPhrase = @"Peach%Pie5";
byte[] byteIVPhrase = Encoding.ASCII.GetBytes(strIVPhrase);
sha256.ComputeHash(byteIVPhrase);
IV = new byte[16];
for (int i = 0; i < 16; i++)
IV[i] = sha256.Hash[i];
sha256.Clear();
}
UseSalt = useSalt;
}
示例11: Decrypt
/// <summary>
/// This is the descrypt method from the ABC4Trust Lite doc appendix B p. 227
/// It will decrypt the chipher based on the N provided.
/// Please note that the smartcard return Big-endian byte stream and descrypt expect
/// little endian data.
/// </summary>
/// <param name="keyPair">keys used to decrypt the data</param>
/// <param name="chipher">data to descrypt</param>
/// <returns>Byte stream of the descrypted data.</returns>
public static byte[] Decrypt(KeyPair keyPair, byte[] chipher)
{
BigInteger d = ModInverse(new BigInteger(3), keyPair.Phi);
BigInteger iChiper = new BigInteger(chipher);
BigInteger plain = BigInteger.ModPow(iChiper, d, keyPair.N);
byte[] NArray = keyPair.N.ToByteArray();
byte[] plainBytes = plain.ToByteArray();
Array.Reverse(plainBytes, 0, plainBytes.Length);
byte[] plainBytesWithZero = new byte[NArray.Length];
Buffer.BlockCopy(plainBytes, 0, plainBytesWithZero, plainBytesWithZero.Length - plainBytes.Length, plainBytes.Length);
byte[] pad = new byte[plainBytesWithZero.Length - 32];
byte[] h = new byte[32];
Buffer.BlockCopy(plainBytesWithZero, 0, pad, 0, pad.Length);
Buffer.BlockCopy(plainBytesWithZero, pad.Length, h, 0, 32);
SHA256 shaM = new SHA256Managed();
byte[] hPrime = shaM.ComputeHash(pad);
if (!Utils.ByteArrayCompare(hPrime, h))
{
Utils.PrintByteArrayToConsole(hPrime);
Utils.PrintByteArrayToConsole(h);
}
shaM.Clear(); //dispose the sha256 object.
byte[] L = new byte[2];
Buffer.BlockCopy(pad, 1, L, 0, 2);
Array.Reverse(L, 0, L.Length);
int LSize = BitConverter.ToInt16(L, 0);
byte[] data = new byte[LSize];
Buffer.BlockCopy(pad, 3, data, 0, data.Length);
return data;
}
示例12: TestReceivedStringHash
public static bool TestReceivedStringHash(string stringWithHash, out string originalStr)
{
if (stringWithHash.Length < 45)
{
originalStr = null;
return (true);
}
var hashCodeString = stringWithHash.Substring(stringWithHash.Length - 44);
var unHashedString = stringWithHash.Substring(0, stringWithHash.Length - 44);
var hashCode = Convert.FromBase64String(hashCodeString);
var encodedUnHashedString = Encoding.Unicode.GetBytes(unHashedString);
var hashingObj = new SHA256Managed();
var receivedHashCode = hashingObj.ComputeHash(encodedUnHashedString);
bool hasBeenTamperedWith = false;
for (int counter = 0; counter < receivedHashCode.Length; counter++)
{
if (receivedHashCode[counter] != hashCode[counter])
{
hasBeenTamperedWith = true;
break;
}
}
if (!hasBeenTamperedWith)
{
originalStr = unHashedString;
}
else
{
originalStr = null;
}
hashingObj.Clear();
return (hasBeenTamperedWith);
}
示例13: SHA256Encrypt
/// <summary>
/// SHA256加密
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string SHA256Encrypt(string str)
{
SHA256 s256 = new SHA256Managed();
byte[] bytes;
bytes = s256.ComputeHash(ASCIIEncoding.Default.GetBytes(str));
s256.Clear();
// 创建一个新的Stringbuilder来保存字节,并且创建一个字符串。
StringBuilder sBuilder = new StringBuilder();
// 循环哈希值的每一个字节,并以十六进制格式保存为字符串
for (int i = 0; i < bytes.Length; i++)
{
sBuilder.Append(bytes[i].ToString("x2"));
}
return sBuilder.ToString();
}
示例14: SHA256Sign
public static string SHA256Sign(string message)
{
var result = string.Empty;
var sha256 = new SHA256Managed();
byte[] s = sha256.ComputeHash(Encoding.UTF8.GetBytes(message));
for (int i = 0; i < s.Length; i++)
{
result += s[i].ToString("X2");
}
sha256.Clear();
return result;
}
示例15: HashAndTransform
private static byte[] HashAndTransform(byte[] pbData, byte[] pbTrfKey32,
ulong uTrfRounds)
{
SHA256Managed sha256 = new SHA256Managed();
byte[] pbHash = sha256.ComputeHash(pbData);
sha256.Clear();
if(!CompositeKey.TransformKeyManaged(pbHash, pbTrfKey32, uTrfRounds))
return null;
sha256 = new SHA256Managed();
pbHash = sha256.ComputeHash(pbHash);
sha256.Clear();
return pbHash;
}