internal void UpdateHash(Stream stream) { byte[] fileHash = CalculateHash(stream, true); if (_snk != null) { if (_snk.PublicOnly) { throw new InvalidOperationException(); } byte[] signature = _snk.SignHash(fileHash); if (signature.Length != _hashSignature.Length) { throw new InvalidOperationException(); } else if (fileHash.Length != _fileHash.Length) { throw new InvalidOperationException(); } _fileHash = fileHash; _hashSignature = signature; } else { _fileHash = fileHash; } stream.Position = _headerPosition; WriteHeader(stream); }
/// <summary> /// Updates the hash. /// </summary> protected virtual void UpdateHash() { byte[] fileHash = CalculateHash(true); _streamHash = fileHash; if (_snk != null) { if (_snk.PublicOnly) { throw new InvalidOperationException(); } byte[] signature = _snk.SignHash(fileHash); if (signature.Length != _hashSignature.Length) { throw new InvalidOperationException(); } else if (fileHash.Length != _streamHash.Length) { throw new InvalidOperationException(); } _hashSignature = signature; } WriteHeader(); }
public void TestMyHash() { StrongNameKey snkIn = StrongNameKey.LoadFrom(SnkFile); byte[] data = new byte[20]; byte[] signature = snkIn.SignHash(data); byte[] publicKeyData = snkIn.GetPublicKeyData(); StrongNameKey snkVerify = StrongNameKey.LoadFrom(publicKeyData); Assert.That(snkVerify.VerifyHash(data, signature), Is.True, "Verification completed"); }