public void TestObfuscateSame() { string obfuscated = this.obfuscator.Obfuscate("test", "testKey"); AssertEquals(obfuscated, this.obfuscator.Obfuscate("test", "testKey")); IObfuscator same = new AesObfuscator(Salt, Package, Device); AssertEquals(obfuscated, same.Obfuscate("test", "testKey")); AssertEquals("test", same.Unobfuscate(obfuscated, "testKey")); }
public void TestUnobfuscateDifferentPackage() { string obfuscated = this.obfuscator.Obfuscate("test", "testKey"); IObfuscator differentPackage = new AesObfuscator(Salt, "package2", Device); try { differentPackage.Unobfuscate(obfuscated, "testKey"); Fail("Should have thrown ValidationException"); } catch (ValidationException) { } }
public void TestUnobfuscateDifferentSalt() { string obfuscated = this.obfuscator.Obfuscate("test", "testKey"); IObfuscator differentSalt = new AesObfuscator(new byte[] { 1 }, Package, Device); try { differentSalt.Unobfuscate(obfuscated, "testKey"); Fail("Should have thrown ValidationException"); } catch (ValidationException) { } }
public void TestUnobfuscateAvoidBadPaddingException() { // Length should be equal to the cipher block size, to make sure that all padding lengths // are accounted for. for (int length = 0; length < 255; length++) { char[] data = Enumerable.Repeat('0', length).ToArray(); string input = Java.Lang.String.ValueOf(data); string obfuscated = this.obfuscator.Obfuscate(input, "testKey"); IObfuscator differentSalt = new AesObfuscator(new byte[] { 1 }, Package, Device); try { differentSalt.Unobfuscate(obfuscated, "testKey"); Fail("Should have thrown ValidationException"); } catch (ValidationException) { } } }