// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseBrowserLink(); app.UseDeveloperExceptionPage(); } else { app.UseExceptionHandler("/Home/Error"); } try { RS256.Configure("key.pem"); //TODO: put the priv key in an environment variable Logger.LogInfo("Crypto Environment Configured"); ; } catch (Exception E) { Logger.LogError("Crypto Config Failed with Exception: " + E.ToString()); } app.UseStaticFiles(); app.UseMvc(routes => { routes.MapRoute( name: "default", template: "{controller=Login}/{action=Login}/{service?}"); }); }
public void GenerateRandomString() { string output = RS256.GenerateRandomString(64); Assert.IsNotEmpty(output); Assert.AreEqual(64, output.Length); }
public ChinaRailwayApp(ulong id, string key, string gateway_url) { this.app_id = id; { var data_serializer = new DataSerializer(new JsonSerializerSettings() { DateFormatString = "yyyy-MM-dd HH:mm:ss.fff", NullValueHandling = NullValueHandling.Ignore, ContractResolver = new Smartunicom.Runtime.Serialization.ContractResolver.JsonSnakeCasePropertyNamesContractResolver() }); var data_signer = new RS256(); data_signer.SetPrivateKey(key); var data_signer_all = new DataSignature(data_signer, data_verifier, data_hs256); { this.order_task = new ChargeTask(this.app_id, data_serializer, data_signer_all, gateway_url); this.payment_task = new PayTask(this.app_id, data_serializer, data_signer_all, gateway_url); this.transfer_task = new TransferTask(this.app_id, data_serializer, data_signer_all, gateway_url); this.webhook_task = new WebHookTask(this.app_id, data_serializer, data_signer_all, gateway_url); this.serializer = new Serializer(data_serializer); } } }
public void EncryptDecrypt() { _rs256Output = RS256.Encrypt(_RS256_INPUT, _PASSWORD); Assert.IsNotEmpty(_rs256Output); string decrypted = RS256.Decrypt(_rs256Output, _PASSWORD).Trim('\0'); Assert.IsNotEmpty(decrypted); Assert.AreEqual(_RS256_INPUT, decrypted); }
static ChinaRailwayApp() { var platform_key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCaB+w+RfL0iuRJT9y0+bgfi8jmatTpQY74vvLmtNa45Yaq2+rs7FdAyVomRralll411kKuYaCqNB3mIUGTT3tCq+c0PIkXk+aAPlUgehRy3FozcFuzO1i6ofq1xs+rJg5XtodX7G+A3rmpUMJ2vexv68rRovBvJKxRkDJsG7BvbQIDAQAB"; { data_verifier = new RS256(); data_verifier.SetPublicKey(platform_key); } var platform_hs_key = "xiZgYsxagQWmtW2cNPA2L9hZ299jGa7wpEiL2SV75OA="; { data_hs256 = new HS256(Convert.FromBase64String(platform_hs_key)); } }
public string GenerateJWT() { JWTHeader Header = new JWTHeader(); JWTBody Payload = new JWTBody { Username = this.Username, Group = this.Group, Iat = DateTime.Now }; string EncodedHeader = Convert.ToBase64String(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(Header))); string EncodedPayload = Convert.ToBase64String(Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(Payload))); string Message = EncodedHeader + "." + EncodedPayload; //TODO: Put the file path in a config file somewhere try { return(Message + "." + RS256.Sign(Encoding.ASCII.GetBytes(Message))); }catch { return("fail!"); } }
public static string Decrypt(string input) { return(RS256.Decrypt(input)); }
public static string Encrypt(string input) { string formatted = $"{input}${_signature}"; return(RS256.Encrypt(formatted)); }
static State() { _signature = RS256.GenerateRandomString(16); }