예제 #1
0
        /// <summary>
        /// Convert recovery phrase to SSB.Keys
        /// </summary>
        /// <param name="words"></param>
        /// <returns></returns>
        public Keys WordsToKeys(string words)
        {
            var wordArr = words.Trim().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            var amount  = wordArr.Length;

            if (amount != 24 && amount != 48)
            {
                throw new ArgumentException("there should be 24 or 48 words");
            }
            var fixedWords = string.Join(" ", SubArray(wordArr, 0, 24));

            BIP39 bip39 = new BIP39(fixedWords, "", BIP39.Language.English);
            var   seed  = bip39.EntropyBytes;

            Rebex.Security.Cryptography.Ed25519 ed25519 = new Rebex.Security.Cryptography.Ed25519();
            ed25519.FromSeed(seed);
            var secretKey = ed25519.GetPrivateKey();
            var publicKey = ed25519.GetPublicKey();

            var _public  = Convert.ToBase64String(publicKey) + ".ed25519";
            var _private = Convert.ToBase64String(secretKey) + ".ed25519";
            var keys     = new Keys
            {
                Curve   = "ed25519",
                Public  = _public,
                Private = _private,
                ID      = "@" + _public,
            };

            return(keys);
        }
예제 #2
0
        public Key(string seed = null)
        {
            _ed25519 = new Rebex.Security.Cryptography.Ed25519();
            _sha256  = new SHA256Managed();
            _ed25519.FromSeed(
                _sha256.ComputeHash(string.IsNullOrEmpty(seed) ? GetSeedKey() : Encoding.UTF8.GetBytes(seed)));

            _publicKey  = _ed25519.GetPublicKey();
            _privateKey = _ed25519.GetPrivateKey();
        }
예제 #3
0
파일: Form1.cs 프로젝트: tkslan/Coin
        private void button1_Click(object sender, EventArgs e)
        {
            var timestamp = System.DateTime.UtcNow.ToFileTimeUtc().ToString();

            using (var hmacsha256 = new HMACSHA256(GetKey()))
            {
                hmacsha256.Initialize();
                var hash    = hmacsha256.ComputeHash(Encoding.UTF8.GetBytes(textBox1.Text));
                var ed25519 = new Rebex.Security.Cryptography.Ed25519();
                ed25519.FromSeed(hash);
                label1.Text = $@"Key:{ByteToString( ed25519.GetPrivateKey())} Hash:{ByteToString(hash)}";
            }
        }
예제 #4
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                var o          = new Rebex.Security.Cryptography.Ed25519();
                var publicKey  = Base58Check.Base58CheckEncoding.EncodePlain(o.GetPublicKey());
                var privateKey = Base58Check.Base58CheckEncoding.EncodePlain(o.GetPrivateKey());

                var user = new ApplicationUser
                {
                    UserName    = model.Email,
                    Email       = model.Email,
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    FullName    = string.Format("{0} {1}.", model.LastName, model.FirstName.Substring(0, 1)),
                    PublicKey   = publicKey,
                    PrivateKey  = privateKey,
                    IsActivated = true,
                    ApiKey      = Guid.NewGuid().ToString()
                };

                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit https://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }