本文整理汇总了C#中System.Security.Cryptography.SHA1CryptoServiceProvider.CopyTo方法的典型用法代码示例。如果您正苦于以下问题:C# SHA1CryptoServiceProvider.CopyTo方法的具体用法?C# SHA1CryptoServiceProvider.CopyTo怎么用?C# SHA1CryptoServiceProvider.CopyTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.SHA1CryptoServiceProvider
的用法示例。
在下文中一共展示了SHA1CryptoServiceProvider.CopyTo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Hash
public static string Hash(string plainText)
{
object[] objArray1 = new object[20];
StringBuilder builder1 = new StringBuilder();
byte[] buffer2 = Encoding.UTF8.GetBytes(plainText);
byte[] buffer1 = new SHA1CryptoServiceProvider().ComputeHash(buffer2);
buffer1.CopyTo(objArray1, 0);
builder1.AppendFormat("{0:X2}{1:X2}{2:X2}{3:X2}{4:X2}{5:X2}{6:X2}{7:X2}{8:X2}{9:X2}", objArray1);
builder1.AppendFormat("{10:X2}{11:X2}{12:X2}{13:X2}{14:X2}{15:X2}{16:X2}{17:X2}{18:X2}{19:X2}", objArray1);
return builder1.ToString();
}
示例2: InitPackage
public void InitPackage()
{
//生成Pre_Master_Secret
byte[] _preMasterSecret = new byte[48];
_preMasterSecret[0] = 3;
_preMasterSecret[1] = 1;
byte[] randomBytes = new byte[46];
Random random = new Random();
random.NextBytes(randomBytes);
Array.Copy(randomBytes, 0, _preMasterSecret, 2, randomBytes.Length);
//生成Master_Secret
App.MasterSecret = Prf10.GenerateBytes(_preMasterSecret, "master secret", App.ClientHelloAndServerHelloRandom, 48);
csTwo.ClientKeyExchangeBase.ContentType = 22;
csTwo.ClientKeyExchangeBase.Version[0] = 3;
csTwo.ClientKeyExchangeBase.Version[1] = 1;
csTwo.ClientKeyExchangeBase.Length[0] = 1;
csTwo.ClientKeyExchangeBase.Length[1] = 6;
csTwo.ClientKeyExchange.HandshakeType = 16;
csTwo.ClientKeyExchange.Length[0] = 0;
csTwo.ClientKeyExchange.Length[1] = 1;
csTwo.ClientKeyExchange.Length[2] = 2;
csTwo.ClientKeyExchange.EncryptedPreMasterlength[0] = 1;
csTwo.ClientKeyExchange.EncryptedPreMasterlength[1] = 0;
var rsa = (RSACryptoServiceProvider)App.PublicKey.Key;
csTwo.ClientKeyExchange.EncryptedPreMaster = rsa.Encrypt(_preMasterSecret, false);
csTwo.ChangeCipherSpecBase.ContentType = 20;
csTwo.ChangeCipherSpecBase.Version[0] = 3;
csTwo.ChangeCipherSpecBase.Version[1] = 1;
csTwo.ChangeCipherSpecBase.Length[0] = 0;
csTwo.ChangeCipherSpecBase.Length[1] = 1;
csTwo.ChangeCipherSpecMessage = 1;
csTwo.EncryptedHandshakeMessageBase.ContentType = 22;
csTwo.EncryptedHandshakeMessageBase.Version[0] = 3;
csTwo.EncryptedHandshakeMessageBase.Version[1] = 1;
App.HandshakeMessage = new byte[App.C_SOneArray.Length - 5 + App.S_COneArray.Length - 5 + 262];
Array.Copy(App.C_SOneArray, 5, App.HandshakeMessage, 0, App.C_SOneArray.Length - 5);
Array.Copy(App.S_COneArray, 5, App.HandshakeMessage, App.C_SOneArray.Length - 5, App.S_COneArray.Length - 5);
App.HandshakeMessage[App.C_SOneArray.Length - 5 + App.S_COneArray.Length - 5 + 1] = csTwo.ClientKeyExchange.HandshakeType;
Array.Copy(csTwo.ClientKeyExchange.Length, 0, App.HandshakeMessage, App.C_SOneArray.Length - 5 + App.S_COneArray.Length - 5 + 1, 3);
Array.Copy(csTwo.ClientKeyExchange.EncryptedPreMasterlength, 0, App.HandshakeMessage, App.C_SOneArray.Length - 5 + App.S_COneArray.Length - 5 + 4, 2);
Array.Copy(csTwo.ClientKeyExchange.EncryptedPreMaster, 0, App.HandshakeMessage, App.C_SOneArray.Length - 5 + App.S_COneArray.Length - 5 + 6, 256);
byte[] md5Hash = new MD5CryptoServiceProvider().ComputeHash(App.HandshakeMessage);
byte[] sha1Hash = new SHA1CryptoServiceProvider().ComputeHash(App.HandshakeMessage);
byte[] hash = new byte[md5Hash.Length + sha1Hash.Length];
md5Hash.CopyTo(hash, 0);
sha1Hash.CopyTo(hash, md5Hash.Length);
byte[] clientVerifyData = Prf10.GenerateBytes(App.MasterSecret, "client finished", hash, 12);
var clientFinishedHeaderBytes = new byte[4];
clientFinishedHeaderBytes[0] = 20;
clientFinishedHeaderBytes[1] = 0;
clientFinishedHeaderBytes[2] = 0;
clientFinishedHeaderBytes[3] = 12;
byte[] keyBlock = Prf10.GenerateBytes(App.MasterSecret, "key expansion", App.SeverHelloAndClientHelloRandom, 66);
byte[] client_write_MAC_secret = new byte[16];
byte[] client_write_key = new byte[16];
Buffer.BlockCopy(keyBlock, 0, client_write_MAC_secret, 0, 16);
Buffer.BlockCopy(keyBlock, 32, client_write_key, 0, 16);
var clientFinishedHash = Hasher.ComputeTlsMD5Hmac(client_write_MAC_secret, 0x16, 0, ByteUtilities.ConcatBytes(clientFinishedHeaderBytes, clientVerifyData));
var clientFinishedDecrypted = ByteUtilities.ConcatBytes(clientFinishedHeaderBytes, clientVerifyData, clientFinishedHash);
Arc4 clientWriteArc4 = new Arc4(client_write_key);
csTwo.EncryptedHandshakeMessage = clientWriteArc4.Encrypt(clientFinishedDecrypted);
csTwo.EncryptedHandshakeMessageBase.Length[0] = 0;
csTwo.EncryptedHandshakeMessageBase.Length[1] = (byte)csTwo.EncryptedHandshakeMessage.Length;
}