本文整理汇总了C#中AssemblyHashAlgorithm类的典型用法代码示例。如果您正苦于以下问题:C# AssemblyHashAlgorithm类的具体用法?C# AssemblyHashAlgorithm怎么用?C# AssemblyHashAlgorithm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AssemblyHashAlgorithm类属于命名空间,在下文中一共展示了AssemblyHashAlgorithm类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AssemblyHash
/// <summary>
/// Constructor
/// </summary>
/// <remarks>If <paramref name="hashAlgo"/> is an unsupported hash algorithm, then
/// <see cref="AssemblyHashAlgorithm.SHA1"/> will be used as the hash algorithm.</remarks>
/// <param name="hashAlgo">The algorithm to use</param>
public AssemblyHash(AssemblyHashAlgorithm hashAlgo) {
switch (hashAlgo) {
case AssemblyHashAlgorithm.MD5:
hasher = MD5.Create();
break;
case AssemblyHashAlgorithm.None:
case AssemblyHashAlgorithm.MD2:
case AssemblyHashAlgorithm.MD4:
case AssemblyHashAlgorithm.SHA1:
case AssemblyHashAlgorithm.MAC:
case AssemblyHashAlgorithm.SSL3_SHAMD5:
case AssemblyHashAlgorithm.HMAC:
case AssemblyHashAlgorithm.TLS1PRF:
case AssemblyHashAlgorithm.HASH_REPLACE_OWF:
default:
hasher = SHA1.Create();
break;
case AssemblyHashAlgorithm.SHA_256:
hasher = SHA256.Create();
break;
case AssemblyHashAlgorithm.SHA_384:
hasher = SHA384.Create();
break;
case AssemblyHashAlgorithm.SHA_512:
hasher = SHA512.Create();
break;
}
}
示例2: GetHash
internal ImmutableArray<byte> GetHash(AssemblyHashAlgorithm algorithmId)
{
using (HashAlgorithm algorithm = TryGetAlgorithm(algorithmId))
{
// ERR_CryptoHashFailed has already been reported:
if (algorithm == null)
{
return ImmutableArray.Create<byte>();
}
switch (algorithmId)
{
case AssemblyHashAlgorithm.None:
case AssemblyHashAlgorithm.Sha1:
return GetHash(ref _lazySHA1Hash, algorithm);
case AssemblyHashAlgorithm.Sha256:
return GetHash(ref _lazySHA256Hash, algorithm);
case AssemblyHashAlgorithm.Sha384:
return GetHash(ref _lazySHA384Hash, algorithm);
case AssemblyHashAlgorithm.Sha512:
return GetHash(ref _lazySHA512Hash, algorithm);
case AssemblyHashAlgorithm.MD5:
return GetHash(ref _lazyMD5Hash, algorithm);
default:
throw ExceptionUtilities.UnexpectedValue(algorithmId);
}
}
}
示例3: AssemblyHash
public AssemblyHash (AssemblyHashAlgorithm algorithm, byte[] value)
{
_algorithm = algorithm;
if (value != null)
_value = (byte[]) value.Clone ();
else
_value = null;
}
示例4: Hash
/// <summary>
/// Hash data
/// </summary>
/// <remarks>If <paramref name="hashAlgo"/> is an unsupported hash algorithm, then
/// <see cref="AssemblyHashAlgorithm.SHA1"/> will be used as the hash algorithm.</remarks>
/// <param name="data">The data</param>
/// <param name="hashAlgo">The algorithm to use</param>
/// <returns>Hashed data or null if <paramref name="data"/> was <c>null</c></returns>
public static byte[] Hash(byte[] data, AssemblyHashAlgorithm hashAlgo) {
if (data == null)
return null;
using (var asmHash = new AssemblyHash(hashAlgo)) {
asmHash.Hash(data);
return asmHash.ComputeHash();
}
}
示例5: Read
public void Read(ClrModuleReader reader)
{
this.HashAlgId = (AssemblyHashAlgorithm)reader.Binary.ReadUInt32();
this.Version = reader.ReadVersion();
this.Flags = (AssemblyFlags)reader.Binary.ReadUInt32();
this.PublicKey = reader.ReadBlob();
this.Name = reader.ReadString();
this.Culture = reader.ReadString();
}
示例6: AssemblyHash
public AssemblyHash(AssemblyHashAlgorithm algorithm, byte[] value) {
_Algorithm = algorithm;
_Value = null;
if (value != null) {
int length = value.Length;
_Value = new byte[length];
Array.Copy(value, _Value, length);
}
}
示例7: AssemblyNameReference
public AssemblyNameReference(string name, Version version)
{
if (name == null)
throw new ArgumentNullException("name");
this.name = name;
this.version = version;
this.hash_algorithm = AssemblyHashAlgorithm.None;
this.token = new MetadataToken(TokenType.AssemblyRef);
}
示例8: Create
public static IncrementalHash Create(AssemblyHashAlgorithm hashAlgorithm)
{
if (PortableShim.IncrementalHash.TypeOpt != null)
{
return new Core(hashAlgorithm);
}
else
{
return new Desktop(hashAlgorithm);
}
}
示例9: AssemblyNameReference
public AssemblyNameReference(string name, string culture, Version version)
{
if (name == null)
throw new ArgumentNullException ("name");
if (culture == null)
throw new ArgumentNullException ("culture");
m_name = name;
m_culture = culture;
m_version = version;
m_hashAlgo = AssemblyHashAlgorithm.None;
}
示例10: AssemblyHash
public AssemblyHash(byte[] value)
{
this._Algorithm = AssemblyHashAlgorithm.SHA1;
this._Value = null;
if (value != null)
{
int length = value.Length;
this._Value = new byte[length];
Array.Copy(value, this._Value, length);
}
}
示例11: AssemblyReference
public AssemblyReference(string name, AssemblyAttributes attributes, Version version, AssemblyHashAlgorithm hashAlgorithm, uint publicKey, string culture)
: base(new MetaDataRow(
(byte)version.Major, (byte)version.Minor, (byte)version.Build, (byte)version.Revision,
(uint)attributes,
publicKey,
0U,
0U,
(uint)hashAlgorithm))
{
this._name = name;
this._culture = culture;
}
示例12: GetHashAlgorithmNameObj
/// <summary>
/// Returns the actual FX implementation of HashAlgorithmName for given hash algorithm id.
/// </summary>
private static object GetHashAlgorithmNameObj(AssemblyHashAlgorithm algorithmId)
{
switch (algorithmId)
{
case AssemblyHashAlgorithm.Sha1:
return PortableShim.HashAlgorithmName.SHA1;
default:
// More algorithms can be added as needed.
throw ExceptionUtilities.UnexpectedValue(algorithmId);
}
}
示例13: LoadData
private void LoadData(CLIFile pFile)
{
HashAlgId = (AssemblyHashAlgorithm)pFile.ReadUInt32();
MajorVersion = pFile.ReadUInt16();
MinorVersion = pFile.ReadUInt16();
BuildNumber = pFile.ReadUInt16();
RevisionNumber = pFile.ReadUInt16();
Flags = (AssemblyFlags)pFile.ReadUInt32();
PublicKey = pFile.ReadBlobHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Blob32Bit));
Name = pFile.ReadStringHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Strings32Bit));
Culture = pFile.ReadStringHeap(pFile.ReadHeapIndex(HeapOffsetSizes.Strings32Bit));
}
示例14: AssemblyHash
public AssemblyHash(AssemblyHashAlgorithm algorithmId, byte[] value)
{
hashAlg = algorithmId;
if(value != null)
{
hash = new byte [value.Length];
Array.Copy(value, hash, value.Length);
}
else
{
hash = null;
}
}
示例15: AssemblyRow
/// <summary>
/// Initializes a new instance of the <see cref="AssemblyRow"/> struct.
/// </summary>
/// <param name="hashAlgId">The hash alg id.</param>
/// <param name="majorVersion">The major version.</param>
/// <param name="minorVersion">The minor version.</param>
/// <param name="buildNumber">The build number.</param>
/// <param name="revision">The revision.</param>
/// <param name="flags">The flags.</param>
/// <param name="publicKey">The public key.</param>
/// <param name="name">The name.</param>
/// <param name="culture">The culture.</param>
public AssemblyRow(AssemblyHashAlgorithm hashAlgId,
ushort majorVersion, ushort minorVersion, ushort buildNumber, ushort revision,
AssemblyAttributes flags, HeapIndexToken publicKey, HeapIndexToken name, HeapIndexToken culture)
{
this.hashAlgId = hashAlgId;
this.majorVersion = majorVersion;
this.minorVersion = minorVersion;
this.buildNumber = buildNumber;
this.revisionNumber = revision;
this.flags = flags;
this.publicKey = publicKey;
this.name = name;
this.culture = culture;
}