예제 #1
0
        /// <summary>Run the command</summary>
        public override int Run()
        {
            // If a file is given, load the data from it
            if (m_filepath.HasValue())
            {
                if (!Path_.FileExists(m_filepath))
                {
                    throw new Exception($"File '{m_filepath}' doesn't exist");
                }

                m_data = File.ReadAllText(m_filepath);
            }

            // If no data is available, error
            if (!m_data.HasValue())
            {
                throw new Exception("No data to generate key from");
            }

            // No private key?
            if (!m_pk.HasValue() || !Path_.FileExists(m_pk))
            {
                throw new Exception($"Private key '{m_pk}' doesn't exist");
            }

            var priv = File.ReadAllText(m_pk);
            var code = ActivationCode.Generate(m_data, priv);
            var key  = Convert.ToBase64String(code);

            // Save to the system clipboard
            if (m_outclip)
            {
                Clipboard.SetText(key);
            }

            // Save to a file
            if (m_outfile.HasValue())
            {
                key.ToFile(m_outfile);
            }

            // Write to StdOut
            Console.WriteLine(key);
            return(0);
        }
예제 #2
0
        [Test] public void ActivationCodeGen1()
        {
                        #if false // Todo: update for .Net standard 2.0
            // Generate a public and private key.
            // Save the public key in the app (in a resource file)
            // Save the private key somewhere safe, you need that to generate more code numbers for the app
            string pub, priv;
            Crypt.GenerateRSAKeyPair(out pub, out priv, 384);
            Assert.NotEqual(pub, priv);

            // This is the licence issuer
            var user_data = "Pauls Test Data";
            var key       = ActivationCode.Generate(user_data, priv);

            // This is the app, checking the licence
            var valid = ActivationCode.Validate(user_data, key, pub);
            Assert.True(valid);
                        #endif
        }
예제 #3
0
        public async Task Register(AuthRegister authRegister)
        {
            var identity = Identity.Create(authRegister.UserId, authRegister.Email,
                                           authRegister.Password, authRegister.PasswordKey);

            await _identityRepository.Create(identity);

            var activationCode = ActivationCode.Generate();

            var code = Code.Create(Code.CodeType.ActivationCode, activationCode, identity.Id);

            await _codeRepository.Create(code);

            var activationCodeEmail = new ActivationCodeEmail
            {
                Email          = identity.Email,
                ActivationCode = code.Value,
                FullName       = authRegister.FullName
            };

            _emailPublisher.SendActivationCode(activationCodeEmail);
        }