protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            if (AppState.State.Instance.UserDetails == null)
            {
                var sharedPrefs = GetSharedPreferences("ChallengeApp", FileCreationMode.Private);

                var userDetailsJson = sharedPrefs.GetString("userDetailsJson", null);

                if (userDetailsJson == null)
                {
                    StartActivity(typeof(TRegisterActivity));
                    Finish();
                    return;
                }

                AppState.State.Instance.UserDetails = JsonConvert.DeserializeObject <Model.UserDetails>(userDetailsJson);
                var kc = new KeyChain.Net.XamarinAndroid.KeyChainHelper(() => this);

                if (Guid.TryParse(kc.GetKey("deviceGuid"), out var guid))
                {
                    AppState.State.Instance.DeviceGuid = guid;
                }
                else
                {
                    StartActivity(typeof(TRegisterActivity));
                    Finish();
                    return;
                }
            }

            SetupDb();
            OnUserDetailsLoaded();
        }
Ejemplo n.º 2
0
        // Crypto

        private string Sign(string data)
        {
            var kc        = new KeyChain.Net.XamarinAndroid.KeyChainHelper(() => this);
            var keyString = kc.GetKey("privateKey");

            RsaPrivateCrtKeyParameters privateKey = (RsaPrivateCrtKeyParameters)PrivateKeyFactory.CreateKey(Convert.FromBase64String(keyString));
            var signer = SignerUtilities.GetSigner("SHA256withRSA");

            signer.Init(true, privateKey);

            var bytes = Encoding.UTF8.GetBytes(data);

            signer.BlockUpdate(bytes, 0, bytes.Length);

            byte[] signature = signer.GenerateSignature();

            var signedString = Convert.ToBase64String(signature);

            return(signedString);
        }