Exemple #1
0
        private void ValidationComplete(UserCookieModel cookie)
        {
            if (cookie != null)
            {
                UserSettingsModel.Instance.Cookie = cookie.AuthCookie;
                byte[] publicKey = null, privateKey = null;

                if (publicKey == null)
                {
                    RsaEncryption.GenerateKeys(out publicKey, out privateKey);
                }

                UserSettingsModel.Instance.PrivateKey = privateKey;
                cookie.User.PublicKey = publicKey;
                UserSettingsModel.Instance.Save(cookie.User);

                YapperServiceProxy.Instance.UpdateUserPublicKey(
                    cookie.User,
                    delegate(bool success)
                {
                    if (!success)
                    {
                        // clear the private key if public key update fails
                        UserSettingsModel.Instance.PrivateKey = null;
                    }
                }
                    );
            }

            Messenger.Default.Send <VerificationCodeValidationCompleteEvent>(new VerificationCodeValidationCompleteEvent(cookie != null));
            this.IsValidating = false;
        }
    public void RsaEncrpytionTest()
    {
        var     rsa  = new RsaEncryption();
        RsaKeys keys = rsa.GenerateKeys();

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

        var encryptedData = rsa.Encrypt(data, keys.publicKey);
        var decryptedData = rsa.Decrypt(encryptedData, keys.privateKey);

        Assert.Equal(data, decryptedData);
    }
    public void RsaSigningTest()
    {
        var     rsa  = new RsaEncryption();
        RsaKeys keys = rsa.GenerateKeys();

        var hmacKey = Encoding.UTF8.GetBytes("HMAC KEY");
        var hmac    = new HmacAuthentication(hmacKey);

        var data = Encoding.UTF8.GetBytes(testMessage);
        var hash = hmac.ComputeHash(data);

        var signature = rsa.SignData(hash, keys.privateKey);
        var isValid   = rsa.VerifySignature(hash, signature, keys.publicKey);

        Assert.True(isValid);
    }
Exemple #4
0
        private void RegistrationCompleted(UserCookieModel userCookie)
        {
            if (userCookie != null && userCookie.User != null)
            {
                byte[] publicKey = null, privateKey = null;

                if (publicKey == null)
                {
                    RsaEncryption.GenerateKeys(out publicKey, out privateKey);
                }

                UserSettingsModel.Instance.PrivateKey = privateKey;
                userCookie.User.PublicKey             = publicKey;
                UserSettingsModel.Instance.Save(userCookie.User);
                UserSettingsModel.Instance.Cookie = userCookie.AuthCookie;

                YapperServiceProxy.Instance.UpdateUserPublicKey(
                    userCookie.User,
                    delegate(bool success)
                {
                    if (!success)
                    {
                        // clear the private key if public key update fails
                        UserSettingsModel.Instance.PrivateKey = null;
                    }
                }
                    );
            }
            else
            {
                this.IsRegistering = false;
            }

            Messenger.Default.Send <RegistrationCompleteEvent>(new RegistrationCompleteEvent()
            {
                User = userCookie == null ? null : userCookie.User
            });
        }