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 TestUnobfuscateDifferentDevice()
 {
     string obfuscated = this.obfuscator.Obfuscate("test", "testKey");
     IObfuscator differentDevice = new AesObfuscator(Salt, Package, "device2");
     try
     {
         differentDevice.Unobfuscate(obfuscated, "testKey");
         Fail("Should have thrown ValidationException");
     }
     catch (ValidationException)
     {
     }
 }
        public override void SetUp()
        {
            var salt = new byte[] { 104, 12, 112, 82, 85, 10, 11, 61, 15, 54, 44, 66, 117, 89, 64, 110, 53, 123, 33 };

            // Prepare PreferenceObfuscator instance
            sp = Context.GetSharedPreferences(Filename, FileCreationMode.Private);
            string deviceId = Settings.Secure.GetString(Context.ContentResolver, Settings.Secure.AndroidId);
            IObfuscator o = new AesObfuscator(salt, Context.PackageName, deviceId);
            op = new PreferenceObfuscator(sp, o);

            // Populate with test data
            op.PutString("testString", "Hello world");
            op.Commit();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            RequestWindowFeature(WindowFeatures.IndeterminateProgress);
            SetContentView(Resource.Layout.Main);

            this.checkLicenseButton = FindViewById<Button>(Resource.Id.MyButton);
            this.checkLicenseButton.Click += delegate { this.DoCheck(); };

            // Try to use more data here. ANDROID_ID is a single point of attack.
            string deviceId = Settings.Secure.GetString(ContentResolver, Settings.Secure.AndroidId);

            // Construct the LicenseChecker with a policy.
            var obfuscator = new AesObfuscator(Salt, this.PackageName, deviceId);
            var policy = new ServerManagedPolicy(this, obfuscator);
            this.checker = new LicenseChecker(this, policy, Base64PublicKey);

            this.DoCheck();
        }
        private void CheckLicense()
        {
            string deviceId = Settings.Secure.GetString(ContentResolver, Settings.Secure.AndroidId);

            // Construct the LicenseChecker with a policy.
            var obfuscator = new AesObfuscator(Salt, PackageName, deviceId);
            var policy = new ServerManagedPolicy(this, obfuscator);
            _licenseChecker = new LicenseChecker(this, policy, Xamarin.InAppBilling.Utilities.Security.Unify(new[] {
					GetNumberString (3),
					GetNumberString (6),
					GetNumberString (1),
					GetNumberString (4),
					GetNumberString (2),
					GetNumberString (7),
					GetNumberString (0),
					GetNumberString (5)
				}, new[] { 0, 1, 2, 3, 4, 5, 6, 7 }));
            _licenseChecker.CheckAccess(this);
        }
 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)
         {
         }
     }
 }
        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"));
        }