private void PackageKeyTest() { CipherDescription cd1 = new CipherDescription( SymmetricEngines.RHX, 192, IVSizes.V128, CipherModes.CTR, PaddingModes.None, BlockSizes.B128, RoundCounts.R22); CSPPrng rnd = new CSPPrng(); byte[] di = new byte[16]; byte[] oi = new byte[16]; byte[] pi = new byte[16]; byte[] pd = new byte[32]; byte[] ti = new byte[16]; rnd.GetBytes(di); rnd.GetBytes(oi); rnd.GetBytes(pi); rnd.GetBytes(pd); rnd.GetBytes(ti); KeyAuthority ka1 = new KeyAuthority(di, oi, pi, pd, KeyPolicies.IdentityRestrict | KeyPolicies.NoExport | KeyPolicies.NoNarrative, 1, ti); MemoryStream mk = new MemoryStream(); PackageKey pk1 = new PackageKey(ka1, cd1, 100); PackageFactory pf = new PackageFactory(mk, ka1); pf.Create(pk1); byte[] bpk = pk1.ToBytes(); PackageKey pk2 = new PackageKey(bpk); if (!pk1.Equals(pk2)) { throw new Exception("KeyFactoryTest: PackageKey serialization has failed!"); } PackageKey pk3 = new PackageKey(mk); if (!pk1.Equals(pk3)) { throw new Exception("KeyFactoryTest: PackageKey serialization has failed!"); } if (pk1.GetHashCode() != pk2.GetHashCode() || pk1.GetHashCode() != pk3.GetHashCode()) { throw new Exception("KeyFactoryTest: PackageKey hash code test has failed!"); } pf.Dispose(); }
public override int GetHashCode() { unchecked { var hashCode = PackageKey.GetHashCode(); hashCode = (hashCode * 397) ^ (int)Action; hashCode = (hashCode * 397) ^ (int)Target; return(hashCode); } }