/// <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); } }
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(); } }
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(); } }
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(); } }
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(); }
private void InitializeMoney() { keyService = new KeyService("1234"); saveKey = keyService.GetKey(); //Prepare KeyPair of Sender api = new DigibyteAPI(new APIOptions { BaseURL = Program.InsightAPI }); LoadData(); }
/// <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"))); })); }
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(); }
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); }
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); }
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; } }
/// <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); } }
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>(); }
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); }
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(); } }
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"))); })); }