public IHttpActionResult PostEmployee(Employee employee) { try { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (DBOperations.IsUsernameExist(employee.UserName)) { return(BadRequest("Username Already Exists")); } if (DBOperations.IsEmailExist(employee.Email_ID)) { return(BadRequest("Email ID Already Exists")); } employee.IsEmailVerified = false; string VerificationCode = Guid.NewGuid().ToString(); var userName = Encode.Base64Encode(employee.UserName); var link = "http://localhost:4200/setpassword/" + HttpUtility.UrlEncode(userName); VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link); db.Employees.Add(employee); db.SaveChanges(); DBOperations.UpdateUserinfo(employee.ID, employee.UserName); CallStoredProc.RunLeaveEntryForNew(employee); return(Ok("Successfully Added")); } catch (Exception ex) { LogFile.WriteLog(ex); return(BadRequest()); } }
private static void signatureHeader(HttpWebRequest httpWebRequest, Request request, string contentMD5) { string uuid = Guid.NewGuid().ToString(); DateTime gmtTime = DateTime.Now; httpWebRequest.Method = request.httpMethod; httpWebRequest.Accept = "application/json"; httpWebRequest.ContentType = "application/json"; httpWebRequest.Date = DateTime.Now; WebHeaderCollection headers = httpWebRequest.Headers; headers.Add("Content-MD5", contentMD5); headers.Add("x-acs-version", request.version); headers.Add("x-acs-signature-nonce", uuid); headers.Add("x-acs-signature-version", request.signatureVersion); headers.Add("x-acs-signature-method", request.signatureMethod); StringBuilder str = new StringBuilder(); str.Append("POST\n") .Append("application/json\n") .Append(contentMD5).Append("\n") .Append("application/json\n") .Append(gmtTime.ToUniversalTime().ToString("r")).Append("\n") .Append("x-acs-signature-method:").Append(request.signatureMethod).Append("\n") .Append("x-acs-signature-nonce:").Append(uuid).Append("\n") .Append("x-acs-signature-version:").Append(request.signatureVersion).Append("\n") .Append("x-acs-version:").Append(request.version).Append("\n") .Append(request.path).Append(request.getQueryString()); string signature = Encode.Base64Encode(Cryptography.HMACSHA1(str.ToString(), request.accessKeySecret)); headers.Add("Authorization", "acs " + request.accessKeyId + ":" + signature); }
private void ButtonBase_OnClick(object sender, RoutedEventArgs e) { Bitmap bitmap = camera.Capture(); string base64 = Encode.Base64Encode(bitmap); File.WriteAllText(@"c:\image.txt", base64); }
public string GenerateSignature(string compactJson, string method, string nonceStr, string privateKey, string requestUrl, string signType, string timestamp, string environment) { string signedData = ""; try { //GenerateSignatureResult result = new GenerateSignatureResult(); string plainText = ""; if (compactJson != "") { string encodedData = Encode.Base64Encode(compactJson); plainText = String.Format("data={0}&method={1}&nonceStr={2}&requestUrl={3}&signType={4}×tamp={5}", encodedData, method, nonceStr, requestUrl, signType, timestamp); } else { plainText = String.Format("method={0}&nonceStr={1}&requestUrl={2}&signType={3}×tamp={4}", method, nonceStr, requestUrl, signType, timestamp); } byte[] plainTextByte = Encoding.UTF8.GetBytes(plainText); RSACryptoServiceProvider provider = PemKeyUtils.GetRSAProviderFromPemFile(privateKey); string prikey = provider.ToXmlString(true); byte[] signedBytes = provider.SignData(plainTextByte, CryptoConfig.MapNameToOID("SHA256")); signedData = Convert.ToBase64String(signedBytes); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(signedData); }
public async Task <IssueVoucherResult> IssueVoucher(string batchKey, string privateKey, string accessToken, string environment) { Object data = new { }; string compactJson = SignatureUtil.GenerateCompactJson(data); string encode = Encode.Base64Encode(compactJson); string method = "post"; string nonceStr = RandomString.GenerateRandomString(32); string requestUrl = ""; if (environment == "sandbox") { requestUrl = String.Concat(Url.SandBoxOpen, "/v3/voucher-batch/" + batchKey + "/issue"); } else if (environment == "production") { requestUrl = String.Concat(Url.ProductionOpen, "/v3/voucher-batch/" + batchKey + "/issue"); } string signType = "sha256"; string timestamp = Convert.ToString((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds); Signature signature = new Signature(); string signatureResult = ""; signatureResult = signature.GenerateSignature(null, method, nonceStr, privateKey, requestUrl, signType, timestamp, environment); signatureResult = "sha256 " + signatureResult; IssueVoucherResult result = new IssueVoucherResult(); try { var content = JsonConvert.SerializeObject(data); var buffer = System.Text.Encoding.UTF8.GetBytes(content); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken); client.DefaultRequestHeaders.Add("X-Nonce-Str", nonceStr); client.DefaultRequestHeaders.Add("X-Signature", signatureResult); client.DefaultRequestHeaders.Add("X-Timestamp", timestamp); var response = await client.PostAsync(requestUrl, byteContent); var responseStr = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { var jsonAsString = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <IssueVoucherResult>(jsonAsString); } else { result = JsonConvert.DeserializeObject <IssueVoucherResult>(response.Content.ReadAsStringAsync().Result); } } catch (Exception ex) { Console.WriteLine("Error", ex.Message); } return(result); }
public async Task <ClientCredentials> RefreshToken(string clientId, string clientSecret, string refreshToken, string environment) { ClientCredentials result = new ClientCredentials(); try { string parameter = String.Concat(clientId, ":", clientSecret); string encodeParameter = Encode.Base64Encode(parameter); string url = ""; if (environment == "sandbox") { url = String.Concat(Url.SandBoxOAuth, "/v1/token"); } else if (environment == "production") { url = String.Concat(Url.ProductionOAuth, "/v1/token"); } var values = new { grantType = "refresh_token", refreshToken = refreshToken }; var content = JsonConvert.SerializeObject(values); var buffer = System.Text.Encoding.UTF8.GetBytes(content); var byteContent = new ByteArrayContent(buffer); byteContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", encodeParameter); var response = await client.PostAsync(url, byteContent); var responseStr = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { var jsonAsString = await response.Content.ReadAsStringAsync(); result = JsonConvert.DeserializeObject <ClientCredentials>(jsonAsString); } else { result = JsonConvert.DeserializeObject <ClientCredentials>(response.Content.ReadAsStringAsync().Result); } } catch (Exception ex) { Console.WriteLine("Error", ex.Message); } return(result); }
protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { var queueName = Console.ReadLine(); queueClient.CreateQueue(queueName); for (int repeatCount = 0; repeatCount < 10; repeatCount++) { var encodedMessage = Encode.Base64Encode($"Hello {repeatCount}"); queueClient.InsertMessage(queueName, encodedMessage); } Console.WriteLine("Messages Added"); await Task.Delay(TimeSpan.FromMinutes(1), stoppingToken); } }
public static string getResponse(Request request) { string postData = JSON.stringify(request.bizData); string contentMD5 = Encode.Base64Encode(Cryptography.MD5(postData)); string url = request.protocol + "://" + request.domain + request.path; string query = request.getQueryString(); HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url + query); signatureHeader(httpWebRequest, request, contentMD5); using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) { streamWriter.Write(postData); streamWriter.Flush(); } HttpWebResponse httpResponse = null; try { httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8)) { string result = streamReader.ReadToEnd(); return(result); } } catch (WebException e) { httpResponse = (HttpWebResponse)e.Response; using (var streamReader = new StreamReader(httpResponse.GetResponseStream(), Encoding.UTF8)) { string result = streamReader.ReadToEnd(); return(result); } } }
public IHttpActionResult ForgotPassword(ForgotPassword pass) { try { var employee = DBOperations.IsEmployeeExist(pass.UserName); if (employee == null) { return(NotFound()); } else { string VerificationCode = Guid.NewGuid().ToString(); var userName = Encode.Base64Encode(employee.UserName); var link = "http://localhost:4200/setpassword/" + HttpUtility.UrlEncode(userName); VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link, "ResetPassword"); return(Ok("Reset Link has been sent to your mail id")); } } catch (Exception ex) { LogFile.WriteLog(ex); return(BadRequest()); } }
public string GetId() => Encode.Base64Encode(Context.ConnectionId);