コード例 #1
0
 /// <summary>
 /// Retrieve key pair from a local data store.
 /// </summary>
 /// <returns>A Cryptokeypair object contains seed, private key, and public key. (BIP44)</returns>
 public CryptoKeyPair GetKey()
 {
     try
     {
         var           data   = collection.FindAll().FirstOrDefault();
         CryptoKeyPair result = new CryptoKeyPair();
         if (!string.IsNullOrEmpty(data?.Seed))
         {
             var hdGenerator = new DigibyteHDGenerator(MainNetwork, "Thai", data.Seed);
             return(hdGenerator.KeyPair(0));
         }
         else if (!string.IsNullOrEmpty(data?.PrivateKey))
         {
             var secretKey = new BitcoinSecret(data.PrivateKey, MainNetwork);
             result.SecretKey = secretKey;
             result.PublicKey = secretKey.GetAddress();
             return(result);
         }
         else
         {
             return(null);
         }
     }
     catch (System.Exception e)
     {
         return(null);
     }
 }
コード例 #2
0
ファイル: Rsa.cs プロジェクト: glihmware/cryptool
    EncryptOAEP512(CryptoKeyPair kp, byte[] plain)
    {
        var rsa = RSA.Create();

        rsa.KeySize = kp.KeySize;

        try
        {
            int n;
            rsa.ImportSubjectPublicKeyInfo(kp.Pub, out n);

            try
            {
                return(rsa.Encrypt(plain, RSAEncryptionPadding.OaepSHA512));
            }
            catch (Exception)
            {
                // Need better way here...
                return(null);
            }
        }
        catch (Exception)
        {
            return(null);
        }
        finally
        {
            rsa.Dispose();
        }
    }
コード例 #3
0
    Sign(CryptoKeyPair kp, byte[] data, string password = null)
    {
        var e = ECDsa.Create();

        e.KeySize = kp.KeySize;

        int n = 0;

        try
        {
            if (!string.IsNullOrEmpty(password))
            {
                e.ImportEncryptedPkcs8PrivateKey(password, kp.Prv, out n);
            }
            else
            {
                e.ImportPkcs8PrivateKey(kp.Prv, out n);
            }

            if (n == 0)
            {
                return(null);
            }

            return(e.SignData(data, HashAlgorithmName.SHA512));
        }
        catch (Exception)
        {
            return(null);
        }
        finally
        {
            e.Dispose();
        }
    }
コード例 #4
0
    Verify(CryptoKeyPair kp, ReadOnlySpan <byte> signature, ReadOnlySpan <byte> data)
    {
        var e = ECDsa.Create();

        e.KeySize = kp.KeySize;

        try
        {
            int n = 0;
            e.ImportSubjectPublicKeyInfo(kp.Pub, out n);

            if (n == 0)
            {
                return(false);
            }

            return(e.VerifyData(data, signature, HashAlgorithmName.SHA512));
        }
        catch (Exception)
        {
            return(false);
        }
        finally
        {
            e.Dispose();
        }
    }
コード例 #5
0
        public async void InitializeEMoney()
        {
            keyService = new KeyService("1234");
            try
            {
                if (!keyService.HasSetupKey())
                {
                    var savekeyForm = new SaveKeyForm();
                    savekeyForm.ShowDialog();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("ไม่ค้นพบกุญแจ");
            }

            saveKey = keyService.GetKey();
            if (saveKey == null)
            {
                Environment.Exit(1);
            }
            privateKey = saveKey.SecretKey;
            publicKey  = saveKey.PublicKeyWif;

            publickeylabel.Text = this.publicKey;

            timer          = new System.Timers.Timer();
            timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
            timer.Interval = 60000;
            timer.Enabled  = true;

            LoadData();
        }
コード例 #6
0
 private void InitializeMoney()
 {
     keyService = new KeyService("1234");
     saveKey    = keyService.GetKey();   //Prepare KeyPair of Sender
     api        = new DigibyteAPI(new APIOptions {
         BaseURL = Program.InsightAPI
     });
     LoadData();
 }
コード例 #7
0
ファイル: UnityConfig.cs プロジェクト: singlag888/aft-regov2
        /// <summary>Registers the type mappings with the Unity container.</summary>
        /// <param name="container">The unity container to configure.</param>
        /// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to
        /// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks>
        public static void RegisterTypes(IUnityContainer container)
        {
            RegisterEventBus(container);

            container.RegisterType <ILog, LogDecorator>();
            container.RegisterType <ITokenProvider, TokenProvider>();

            //use of explicit factory method to prevent Func from doing property injection
            //and stuffing your public properties with nulls (surprise!)
            container.RegisterType <IRepository>(ReuseWithinRequest, new InjectionFactory(c => new Repository()));

            container.RegisterType <IWalletOperations, WalletOperations>();
            container.RegisterType <ISynchronizationService, SynchronizationService>();
            container.RegisterType <IUgsServiceBus, FakeUgsServiceBus>();

            container.RegisterType <ISettingsRepository, SettingsRepository>();
            container.RegisterType <ISettingsQueries, SettingsQueries>();
            container.RegisterType <IUgsServiceBusSettingsProvider, UgsServiceBusSettingsProvider>();
            container.RegisterType <ICommonSettingsProvider, CommonSettingsProvider>();

            container.RegisterType <IRepositoryBase, RepositoryBase>();
            container.RegisterType <ISynchronizationService, SynchronizationService>();
            container.RegisterType <IJsonSerializationProvider, JsonSerializationProvider>();
            container.RegisterType <IWebConfigProvider, WebConfigProvider>();
            container.RegisterType <ITokenProvider, TokenProvider>();
            container.RegisterType <IErrorManager, ErrorManager>();
            container.RegisterType <ITokenValidationProvider, TokenValidationProvider>();
            container.RegisterType <IGameProviderLog, GameProviderLog>();
            container.RegisterType <ITransactionScopeProvider, TransactionScopeProvider>();
            container.RegisterType <IGameCommands, GameCommands>();
            container.RegisterType <IGameQueries, GameQueries>();
            container.RegisterType <ICommonGameActionsProvider, CommonGameActionsProvider>();
            container.RegisterType <IGameManagement, GameManagement>();
            container.RegisterType <IGameWalletOperations, GameWalletOperations>();
            container.RegisterType <IGameWalletQueries, GameWalletQueries>();
            container.RegisterType <IPlayerCommands, PlayerCommands>();
            container.RegisterType <IGameEventsProcessor, GameEventsProcessor>();
            container.RegisterType <IFlycowApiClientSettingsProvider, FlycowApiClientSettingsProvider>();
            container.RegisterType <IModeSwitch, ModeSwitch>();
            container.RegisterType <IFlycowApiClientProvider, FlycowApiClientProvider>();

            container.RegisterType <ICryptoKeyPair>("authServer", NewEachTime, new InjectionFactory(c =>
            {
                var config = c.Resolve <IWebConfigProvider>();
                return(CryptoKeyPair.LoadCertificate(
                           HostingEnvironment.MapPath(config.GetAppSettingByKey("CertificateLocation")),
                           config.GetAppSettingByKey("CertificatePassword")));
            }));

            container.RegisterType <ICryptoKeyPair>("dataServer", NewEachTime, new InjectionFactory(c =>
            {
                var config = c.Resolve <IWebConfigProvider>();
                return(CryptoKeyPair.LoadCertificate(
                           HostingEnvironment.MapPath(config.GetAppSettingByKey("CertificateLocation")),
                           config.GetAppSettingByKey("CertificatePassword")));
            }));
        }
コード例 #8
0
        private void InitializeMoney()
        {
            keyService = new KeyService("1234");
            saveKey    = keyService.GetKey();   //Prepare KeyPair of Sender
            api        = new DigibyteAPI(new APIOptions {
                BaseURL = Program.InsightAPI
            });

            t = new Thread(new ThreadStart(SendDGB));
            t.Start();
        }
コード例 #9
0
        public OAuth2Controller()
        {
            // In this example, we're just newing up an auth server. A real implementation would use an IOC container
            // to resolve the dependencies and inject the auth server into our controller.
            var authServerKeys    = CryptoKeyPair.LoadCertificate(HostingEnvironment.MapPath("~/bin/Certificates/auth-server.pfx"), "p@ssw0rd");
            var dataServerKeys    = CryptoKeyPair.LoadCertificate(HostingEnvironment.MapPath("~/bin/Certificates/data-server.pfx"), "p@ssw0rd");
            var exampleAuthServer = new ExampleAuthorizationServer(new FakeCryptoKeyStore(),
                                                                   authServerKeys, dataServerKeys, new FakeOAuth2ClientStore(), new FakeUserStore());

            this.authServer = new AuthorizationServer(exampleAuthServer);
        }
コード例 #10
0
        public MockSunbetTokenController(IRepository repository)
        {
            var authCertificateLocation = HostingEnvironment.MapPath(WebConfigurationManager.AppSettings["CertificateLocation"]);

            var authCryptoKeyPair = CryptoKeyPair.LoadCertificate(authCertificateLocation, WebConfigurationManager.AppSettings["CertificatePassword"]);

            var gameProviderStore = new GameProviderOAuthStore(repository);

            var regoAuthServer = new GameApiOAuthServer(new CryptoKeyStore(),
                                                        authCryptoKeyPair,
                                                        authCryptoKeyPair,
                                                        gameProviderStore,
                                                        _gameProviderId);

            _authServer = new AuthorizationServer(regoAuthServer);
        }
コード例 #11
0
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            var result = keyService.ParsePrivateKey(textBox1.Text);

            if (result != null)
            {
                currentKeyPair  = result;
                textBox2.Text   = result.PublicKeyWif;
                button1.Enabled = true;
            }
            else
            {
                textBox2.Text   = null;
                button1.Enabled = false;
            }
        }
コード例 #12
0
 /// <summary>
 /// Update or Insert a Cryptokeypair object to local data store.
 /// </summary>
 /// <param name="keyPair">A Cryptokeypair object.</param>
 /// <returns>True if operation is successful. Otherwise returns false.</returns>
 public bool SaveKey(CryptoKeyPair keyPair)
 {
     try
     {
         collection.Delete(c => true);
         var data = new KeyData()
         {
             Seed       = keyPair.Seed,
             PrivateKey = keyPair.SecretKeyWif,
             PublicKey  = keyPair.PublicKeyWif
         };
         collection.Upsert(data);
         return(true);
     }
     catch (System.Exception e)
     {
         return(false);
     }
 }
コード例 #13
0
        public override void Configure(Funq.Container container)
        {
            //Set JSON web services to return idiomatic JSON camelCase properties
            ServiceStack.Text.JsConfig.EmitCamelCaseNames = true;

            //Configure User Defined REST Paths
            Routes
            .Add <Users>("/users")
            .Add <Users>("/users/{Username}");

            //Register all your dependencies
            ;


            container.Register("authServer", c =>
                               CryptoKeyPair.LoadCertificate(HostingEnvironment.MapPath("~/bin/Certificates/auth-server.pfx"), "p@ssw0rd"));
            container.Register("dataServer", c =>
                               CryptoKeyPair.LoadCertificate(HostingEnvironment.MapPath("~/bin/Certificates/data-server.pfx"), "p@ssw0rd"));
            container.RegisterAutoWiredAs <FakeUserStore, IUserStore>();
        }
コード例 #14
0
    GenerateKey(int keySize = 521, string password = null)
    {
        var e = ECDsa.Create();

        e.KeySize = keySize;

        var kp = new CryptoKeyPair()
        {
            KeySize = keySize
        };

        try
        {
            if (!string.IsNullOrEmpty(password))
            {
                var pbe = new PbeParameters(
                    PbeEncryptionAlgorithm.Aes256Cbc,
                    HashAlgorithmName.SHA512, 1000);

                kp.Prv = e.ExportEncryptedPkcs8PrivateKey(password, pbe);
            }
            else
            {
                kp.Prv = e.ExportPkcs8PrivateKey();
            }

            kp.Pub     = e.ExportSubjectPublicKeyInfo();
            kp.KeySize = keySize;
        }
        catch (Exception)
        {
            return(null);
        }
        finally
        {
            e.Dispose();
        }

        return(kp);
    }
コード例 #15
0
ファイル: Rsa.cs プロジェクト: glihmware/cryptool
    DecryptOAEP512(CryptoKeyPair kp, byte[] cipher, string password = null)
    {
        var rsa = RSA.Create();

        rsa.KeySize = kp.KeySize;

        try
        {
            int n;
            if (!string.IsNullOrEmpty(password))
            {
                rsa.ImportEncryptedPkcs8PrivateKey(password, kp.Prv, out n);
            }
            else
            {
                rsa.ImportPkcs8PrivateKey(kp.Prv, out n);
            }

            try
            {
                return(rsa.Decrypt(cipher, RSAEncryptionPadding.OaepSHA512));
            }
            catch (Exception)
            {
                // Need better way here...
                return(null);
            }
        }
        catch (Exception)
        {
            return(null);
        }
        finally
        {
            rsa.Dispose();
        }
    }
コード例 #16
0
        private void SetupGameApiDependencies(IUnityContainer container)
        {
            container.RegisterInstance(container);
            container.RegisterType <IJsonSerializationProvider, JsonSerializationProvider>(ReuseWithinContainer);
            container.RegisterType <IWebConfigProvider, WebConfigProvider>(ReuseWithinContainer);
            container.RegisterType <ITokenProvider, TokenProvider>(ReuseWithinContainer);
            container.RegisterType <IErrorManager, ErrorManager>(ReuseWithinContainer);
            container.RegisterType <ITokenValidationProvider, TokenValidationProvider>(ReuseWithinContainer);
            container.RegisterType <IGameProviderLog, GameProviderLog>(ReuseWithinContainer);
            container.RegisterType <ITransactionScopeProvider, TransactionScopeProvider>(ReuseWithinContainer);
            container.RegisterType <IGameRepository, GameRepository>(NewEachTime);
            container.RegisterType <IGameCommands, GameCommands>(NewEachTime);
            container.RegisterType <IGameQueries, GameQueries>(NewEachTime);
            container.RegisterType <ICommonGameActionsProvider, CommonGameActionsProvider>(NewEachTime);

            //use of explicit factory method to prevent Func from doing property injection
            //and stuffing your public properties with nulls (surprise!)
            container.RegisterType <IGameRepository>(ReuseWithinRequest,
                                                     new InjectionFactory(c => new GameRepository()));

            container.RegisterType <ICryptoKeyPair>("authServer", NewEachTime, new InjectionFactory(c =>
            {
                var config = c.Resolve <IWebConfigProvider>();
                return(CryptoKeyPair.LoadCertificate(
                           HostingEnvironment.MapPath(config.GetAppSettingByKey("CertificateLocation")),
                           config.GetAppSettingByKey("CertificatePassword")));
            }));

            container.RegisterType <ICryptoKeyPair>("dataServer", NewEachTime, new InjectionFactory(c =>
            {
                var config = c.Resolve <IWebConfigProvider>();
                return(CryptoKeyPair.LoadCertificate(
                           HostingEnvironment.MapPath(config.GetAppSettingByKey("CertificateLocation")),
                           config.GetAppSettingByKey("CertificatePassword")));
            }));
        }