Code development platform for open source projects from the European Union institutions

Skip to content
Snippets Groups Projects
Commit 3f8ca2b0 authored by Markus Quaritsch's avatar Markus Quaritsch
Browse files

comparison of two different implementations to create the hash, both yield the same result!

parent 17659b21
No related branches found
No related tags found
No related merge requests found
......@@ -58,6 +58,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoCore BugReportTests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoHashing", "VectoCommon\VectoHashing\VectoHashing.csproj", "{B673E12F-D323-4C4C-8805-9915B2C72D3D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "VectoHashingTest", "VectoCommon\VectoHashingTest\VectoHashingTest.csproj", "{760C1C5B-A767-463E-BA85-F0BCFC23A550}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
......@@ -236,6 +238,14 @@ Global
{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Release|Any CPU.Build.0 = Release|Any CPU
{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Release|x64.ActiveCfg = Release|Any CPU
{B673E12F-D323-4C4C-8805-9915B2C72D3D}.Release|x86.ActiveCfg = Release|Any CPU
{760C1C5B-A767-463E-BA85-F0BCFC23A550}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{760C1C5B-A767-463E-BA85-F0BCFC23A550}.Debug|Any CPU.Build.0 = Debug|Any CPU
{760C1C5B-A767-463E-BA85-F0BCFC23A550}.Debug|x64.ActiveCfg = Debug|Any CPU
{760C1C5B-A767-463E-BA85-F0BCFC23A550}.Debug|x86.ActiveCfg = Debug|Any CPU
{760C1C5B-A767-463E-BA85-F0BCFC23A550}.Release|Any CPU.ActiveCfg = Release|Any CPU
{760C1C5B-A767-463E-BA85-F0BCFC23A550}.Release|Any CPU.Build.0 = Release|Any CPU
{760C1C5B-A767-463E-BA85-F0BCFC23A550}.Release|x64.ActiveCfg = Release|Any CPU
{760C1C5B-A767-463E-BA85-F0BCFC23A550}.Release|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......@@ -258,5 +268,6 @@ Global
{2C58BA97-2954-4D19-920F-A24B78FC80A4} = {D29E62A2-CF08-469F-B29F-1B25DCB35386}
{7C364099-9B85-473A-8A42-BBEBE4798FF5} = {CC93EA68-F3FE-4BCB-9292-1101F94A4D09}
{B673E12F-D323-4C4C-8805-9915B2C72D3D} = {73A5BF70-6168-456F-95E5-A1402BFA488C}
{760C1C5B-A767-463E-BA85-F0BCFC23A550} = {73A5BF70-6168-456F-95E5-A1402BFA488C}
EndGlobalSection
EndGlobal
......@@ -42,6 +42,7 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="XmlHashProvider.cs" />
<Compile Include="XmlHashTest.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
......
......@@ -4,7 +4,7 @@ using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Xml;
namespace VectoDB
namespace TUGraz.VectoHashing
{
public class XmlHashProvider
{
......@@ -17,10 +17,10 @@ namespace VectoDB
public string ComputeHash(string xpath)
{
var xml = new XmlDocument() { PreserveWhitespace = true };
var xml = new XmlDocument();
var manager = new XmlNamespaceManager(xml.NameTable);
manager.AddNamespace("ved", "urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.6");
manager.AddNamespace("tns", "urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.6");
manager.AddNamespace("ved", "urn:tugraz:ivt:VectoAPI:EngineeringDefinitions:v0.8");
manager.AddNamespace("tns", "urn:tugraz:ivt:VectoAPI:EngineeringInput:v0.8");
using (var fs = new FileStream(File, FileMode.Open)) {
using (var sr = new StreamReader(fs)) {
......
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.Xml;
using System.Text;
using System.Xml;
namespace TUGraz.VectoHashing
{
public class XmlHashTest
{
public string ComputeHash(XmlDocument doc)
{
var signedXml = new SignedXml(doc);
var reference = new Reference("#elemID") {
DigestMethod = "http://www.w3.org/2001/04/xmlenc#sha256"
};
reference.AddTransform(new XmlDsigC14NTransform());
//reference.AddTransform(new XmlDsigVectoTransform());
signedXml.AddReference(reference);
signedXml.ComputeSignature(HMAC.Create());
var xmlDigitalSignature = reference.GetXml();
var sig = doc.CreateElement("Signature");
sig.AppendChild(doc.ImportNode(xmlDigitalSignature, true));
doc.DocumentElement.AppendChild(sig);
if (doc.FirstChild is XmlDeclaration) {
doc.RemoveChild(doc.FirstChild);
}
var xmltw = new XmlTextWriter("simple_document_hashed.xml", new UTF8Encoding(false));
doc.WriteTo(xmltw);
xmltw.Close();
var references = signedXml.SignedInfo.References;
return Convert.ToBase64String(((Reference)references[0]).DigestValue);
}
}
}
\ No newline at end of file
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("VectoHashingTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("VectoHashingTest")]
[assembly: AssemblyCopyright("Copyright © 2017")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("bd51185f-fccf-42e3-b3e1-c59fcd74134a")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
<?xml version="1.0" encoding="UTF-8"?>
<root>
<element id="elemID">
<message>hello world</message>
</element>
</root>
using System;
using System.Xml;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using TUGraz.VectoHashing;
namespace VectoHashingTest
{
[TestClass]
public class UnitTest1
{
public const string SimpleXML = @"Testdata\XML\simple_document.xml";
[TestMethod]
public void TestCompareHashing()
{
var hasher1 = new XmlHashProvider(SimpleXML);
var hash1 = hasher1.ComputeHash("//*[@id='elemID']");
var doc = new XmlDocument();
doc.Load(SimpleXML);
var hasher2 = new XmlHashTest();
var hash2 = hasher2.ComputeHash(doc);
Assert.AreEqual(hash1, hash2);
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{760C1C5B-A767-463E-BA85-F0BCFC23A550}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>VectoHashingTest</RootNamespace>
<AssemblyName>VectoHashingTest</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
<IsCodedUITest>False</IsCodedUITest>
<TestProjectType>UnitTest</TestProjectType>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
</ItemGroup>
<Choose>
<When Condition="('$(VisualStudioVersion)' == '10.0' or '$(VisualStudioVersion)' == '') and '$(TargetFrameworkVersion)' == 'v3.5'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
</ItemGroup>
</When>
<Otherwise>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework" />
</ItemGroup>
</Otherwise>
</Choose>
<ItemGroup>
<Compile Include="UnitTest1.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<Content Include="Testdata\XML\simple_document.xml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\VectoHashing\VectoHashing.csproj">
<Project>{B673E12F-D323-4C4C-8805-9915B2C72D3D}</Project>
<Name>VectoHashing</Name>
</ProjectReference>
</ItemGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '10.0' And '$(IsCodedUITest)' == 'True'">
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.CodedUITestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITest.Extension, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestTools.UITesting, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<Private>False</Private>
</Reference>
</ItemGroup>
</When>
</Choose>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment