public static void TestComparisons() { AesKey key1 = new AesKey(new byte[] { 5, 6, 7, 8, 2, 4, 55, 77, 34, 65, 89, 12, 45, 87, 54, 255 }); AesKey key2 = new AesKey(new byte[] { 5, 6, 7, 8, 2, 4, 55, 77, 34, 65, 89, 12, 45, 87, 54, 255 }); KeyWrapSalt salt1 = new KeyWrapSalt(AesKey.DefaultKeyLength); KeyWrapSalt salt2 = new KeyWrapSalt(AesKey.DefaultKeyLength); AesKeyThumbprint thumbprint1a = new AesKeyThumbprint(key1, salt1, 13); AesKeyThumbprint thumbprint1a_alias = thumbprint1a; AesKeyThumbprint thumbprint1b = new AesKeyThumbprint(key1, salt2, 25); AesKeyThumbprint thumbprint2a = new AesKeyThumbprint(key2, salt2, 25); AesKeyThumbprint thumbprint2b = new AesKeyThumbprint(key2, salt1, 13); AesKeyThumbprint nullThumbprint = null; Assert.That(thumbprint1a == thumbprint1a_alias, "Same instance should of course compare equal."); Assert.That(nullThumbprint != thumbprint1a, "A null should not compare equal to any other instance."); Assert.That(thumbprint1a != nullThumbprint, "A null should not compare equal to any other instance."); Assert.That(thumbprint1a == thumbprint2b, "Same raw key and salt, but different instance, should compare equal."); Assert.That(thumbprint1b == thumbprint2a, "Same raw key and salt, but different instance, should compare equal."); Assert.That(thumbprint1a != thumbprint1b, "Same raw key but different salt, should compare inequal."); Assert.That(thumbprint2a != thumbprint2b, "Same raw key but different salt, should compare inequal."); object object1a = thumbprint1a; object object2b = thumbprint2b; Assert.That(object1a.Equals(nullThumbprint), Is.False, "An instance does not equals null."); Assert.That(object1a.Equals(object2b), Is.True, "The two instances are equivalent."); object badTypeObject = key1; Assert.That(object1a.Equals(badTypeObject), Is.False, "The object being compared to is of the wrong type."); }
private void Initialize(IRuntimeFileInfo encryptedFileInfo, IRuntimeFileInfo decryptedFileInfo, DateTime lastWriteTimeUtc, AesKey key, AesKeyThumbprint thumbprint, ActiveFileStatus status, ILauncher process) { EncryptedFileInfo = OS.Current.FileInfo(encryptedFileInfo.FullName); DecryptedFileInfo = OS.Current.FileInfo(decryptedFileInfo.FullName); Key = key; Thumbprint = thumbprint; Status = status; LastActivityTimeUtc = OS.Current.UtcNow; Process = process; LastEncryptionWriteTimeUtc = lastWriteTimeUtc; }
public static void TestThumbprint() { AesKey key1 = new AesKey(new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }); AesKeyThumbprint originalThumbprint = key1.Thumbprint; Assert.That(originalThumbprint, Is.EqualTo(key1.Thumbprint), "The thumbprints should be the same."); key1.Thumbprint = new AesKeyThumbprint(key1, new KeyWrapSalt(AesKey.DefaultKeyLength), OS.Current.KeyWrapIterations); Assert.That(originalThumbprint, Is.Not.EqualTo(key1.Thumbprint), "The thumbprints should differ."); }
public static void TestGetHashCode() { AesKey key1 = new AesKey(new byte[] { 5, 6, 7, 8, 2, 4, 55, 77, 34, 65, 89, 12, 45, 87, 54, 255 }); AesKey key2 = new AesKey(new byte[] { 5, 6, 7, 8, 2, 4, 55, 77, 34, 65, 89, 12, 45, 87, 54, 255 }); KeyWrapSalt salt1 = new KeyWrapSalt(AesKey.DefaultKeyLength); KeyWrapSalt salt2 = new KeyWrapSalt(AesKey.DefaultKeyLength); AesKeyThumbprint thumbprint1a = new AesKeyThumbprint(key1, salt1, 17); AesKeyThumbprint thumbprint1b = new AesKeyThumbprint(key1, salt2, 17); AesKeyThumbprint thumbprint2a = new AesKeyThumbprint(key2, salt2, 17); Assert.That(thumbprint1a.GetHashCode() != thumbprint1b.GetHashCode(), "The salt is different, so the hash code should be different."); Assert.That(thumbprint1b.GetHashCode() == thumbprint2a.GetHashCode(), "The keys are equivalent, and the salt the same, so the hash code should be different."); }
public static void TestAesKeyThumbprintMethods() { AesKey key1 = new AesKey(new byte[] { 5, 6, 7, 8, 2, 4, 55, 77, 34, 65, 89, 12, 45, 87, 54, 255 }); AesKey key2 = new AesKey(new byte[] { 5, 6, 7, 8, 2, 4, 55, 77, 34, 65, 89, 12, 45, 87, 54, 255 }); KeyWrapSalt salt1 = new KeyWrapSalt(16); KeyWrapSalt salt2 = new KeyWrapSalt(salt1.GetBytes()); AesKeyThumbprint thumbprint1 = new AesKeyThumbprint(key1, salt1, 10); AesKeyThumbprint thumbprint2 = new AesKeyThumbprint(key2, salt2, 10); Assert.That(thumbprint1 == thumbprint2, "Two thumb prints made from the same key and salt bytes, although different AesKey instances should be equivalent."); AesKeyThumbprint thumbprint3 = new AesKeyThumbprint(new AesKey(), new KeyWrapSalt(AesKey.DefaultKeyLength), 10); Assert.That(thumbprint2 != thumbprint3, "Two very different keys and salts should not be equivalent."); }