using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Security.Cryptography;
using System.Text;
namespace System.Security.Policy
{
/// Provides evidence about the hash value for an assembly. This class cannot be inherited.
// Token: 0x0200058D RID: 1421
[ComVisible(true)]
[Serializable]
public sealed class Hash : ISerializable, IBuiltInEvidence
{
/// Initializes a new instance of the class.
/// The for which to compute the hash value.
/// The parameter is null.
// Token: 0x06003400 RID: 13312 RVA: 0x000B2D08 File Offset: 0x000B0F08
public Hash(Assembly assembly)
{
if (assembly == null)
{
throw new ArgumentNullException("assembly");
}
this.assembly = assembly;
}
// Token: 0x06003401 RID: 13313 RVA: 0x000B2D28 File Offset: 0x000B0F28
internal Hash()
{
}
// Token: 0x06003402 RID: 13314 RVA: 0x000B2D30 File Offset: 0x000B0F30
internal Hash(SerializationInfo info, StreamingContext context)
{
this.data = (byte[])info.GetValue("RawData", typeof(byte[]));
}
// Token: 0x06003403 RID: 13315 RVA: 0x000B2D64 File Offset: 0x000B0F64
int IBuiltInEvidence.GetRequiredSize(bool verbose)
{
return (!verbose) ? 0 : 5;
}
// Token: 0x06003404 RID: 13316 RVA: 0x000B2D74 File Offset: 0x000B0F74
[MonoTODO("IBuiltInEvidence")]
int IBuiltInEvidence.InitFromBuffer(char[] buffer, int position)
{
return 0;
}
// Token: 0x06003405 RID: 13317 RVA: 0x000B2D78 File Offset: 0x000B0F78
[MonoTODO("IBuiltInEvidence")]
int IBuiltInEvidence.OutputToBuffer(char[] buffer, int position, bool verbose)
{
return 0;
}
/// Gets the hash value for the assembly.
/// A byte array that represents the hash value for the assembly.
// Token: 0x17000A3E RID: 2622
// (get) Token: 0x06003406 RID: 13318 RVA: 0x000B2D7C File Offset: 0x000B0F7C
public byte[] MD5
{
get
{
if (this._md5 != null)
{
return this._md5;
}
if (this.assembly == null && this._sha1 != null)
{
string text = Locale.GetText("No assembly data. This instance was initialized with an MSHA1 digest value.");
throw new SecurityException(text);
}
HashAlgorithm hashAlgorithm = global::System.Security.Cryptography.MD5.Create();
this._md5 = this.GenerateHash(hashAlgorithm);
return this._md5;
}
}
/// Gets the hash value for the assembly.
/// A byte array that represents the hash value for the assembly.
// Token: 0x17000A3F RID: 2623
// (get) Token: 0x06003407 RID: 13319 RVA: 0x000B2DDC File Offset: 0x000B0FDC
public byte[] SHA1
{
get
{
if (this._sha1 != null)
{
return this._sha1;
}
if (this.assembly == null && this._md5 != null)
{
string text = Locale.GetText("No assembly data. This instance was initialized with an MD5 digest value.");
throw new SecurityException(text);
}
HashAlgorithm hashAlgorithm = global::System.Security.Cryptography.SHA1.Create();
this._sha1 = this.GenerateHash(hashAlgorithm);
return this._sha1;
}
}
/// Computes the hash value for the assembly using the specified hash algorithm.
/// A byte array that represents the hash value for the assembly.
/// The hash algorithm to use to compute the hash value for the assembly.
/// The parameter is null.
/// The hash value for the assembly cannot be generated.
///
///
///
///
// Token: 0x06003408 RID: 13320 RVA: 0x000B2E3C File Offset: 0x000B103C
public byte[] GenerateHash(HashAlgorithm hashAlg)
{
if (hashAlg == null)
{
throw new ArgumentNullException("hashAlg");
}
return hashAlg.ComputeHash(this.GetData());
}
/// Gets the object with the parameter name and additional exception information.
/// The object that holds the serialized object data.
/// The contextual information about the source or destination.
///
///
///
// Token: 0x06003409 RID: 13321 RVA: 0x000B2E5C File Offset: 0x000B105C
public void GetObjectData(SerializationInfo info, StreamingContext context)
{
if (info == null)
{
throw new ArgumentNullException("info");
}
info.AddValue("RawData", this.GetData());
}
/// Returns a string representation of the current .
/// A representation of the current .
// Token: 0x0600340A RID: 13322 RVA: 0x000B2E8C File Offset: 0x000B108C
public override string ToString()
{
SecurityElement securityElement = new SecurityElement(base.GetType().FullName);
securityElement.AddAttribute("version", "1");
StringBuilder stringBuilder = new StringBuilder();
byte[] array = this.GetData();
for (int i = 0; i < array.Length; i++)
{
stringBuilder.Append(array[i].ToString("X2"));
}
securityElement.AddChild(new SecurityElement("RawData", stringBuilder.ToString()));
return securityElement.ToString();
}
// Token: 0x0600340B RID: 13323 RVA: 0x000B2F10 File Offset: 0x000B1110
private byte[] GetData()
{
if (this.assembly == null && this.data == null)
{
string text = Locale.GetText("No assembly data.");
throw new SecurityException(text);
}
if (this.data == null)
{
FileStream fileStream = new FileStream(this.assembly.Location, FileMode.Open, FileAccess.Read);
this.data = new byte[fileStream.Length];
fileStream.Read(this.data, 0, (int)fileStream.Length);
}
return this.data;
}
/// Creates a object containing an hash value.
/// A object containing the hash value provided by the parameter.
/// A byte array containing an hash value.
/// The parameter is null.
// Token: 0x0600340C RID: 13324 RVA: 0x000B2F90 File Offset: 0x000B1190
public static Hash CreateMD5(byte[] md5)
{
if (md5 == null)
{
throw new ArgumentNullException("md5");
}
return new Hash
{
_md5 = md5
};
}
/// Creates a object containing an hash value.
/// A object containing the hash value provided by the parameter.
/// A byte array containing a hash value.
/// The parameter is null.
// Token: 0x0600340D RID: 13325 RVA: 0x000B2FBC File Offset: 0x000B11BC
public static Hash CreateSHA1(byte[] sha1)
{
if (sha1 == null)
{
throw new ArgumentNullException("sha1");
}
return new Hash
{
_sha1 = sha1
};
}
// Token: 0x04001551 RID: 5457
private Assembly assembly;
// Token: 0x04001552 RID: 5458
private byte[] data;
// Token: 0x04001553 RID: 5459
internal byte[] _md5;
// Token: 0x04001554 RID: 5460
internal byte[] _sha1;
}
}