Skip to content

Instantly share code, notes, and snippets.

View daonhan's full-sized avatar
🎯
Focusing

Paul Nhan Nguyen Dao daonhan

🎯
Focusing
View GitHub Profile
@daonhan
daonhan / XmlLinqConversionExtensions.cs
Created June 16, 2023 07:29 — forked from ChuckSavage/XmlLinqConversionExtensions.cs
Convert To/From XmlDocument and XDocument/XElements
using System.Xml;
using System.Xml.Linq;
namespace XmlLib
{
/// <summary>
/// Provides extension methods for simple conversion between System.Xml and System.Xml.Linq classes.
/// </summary>
/// <remarks>From: http://brianary.blogspot.com/2010/02/converting-between-xdocument-and.html</remarks>
public static class XmlLinqConversionExtensions
public class AuthenticatingHandler<T> : DelegatingHandler where T : ISecurityTokenAccessor
{
private readonly Policy<HttpResponseMessage> _policy;
private readonly T _securityTokenAccessor;
private IAccessToken _accessToken;
private AuthenticationHeaderValue _authenticationHeader;
public AuthenticatingHandler(T securityTokenAccessor)
{
_securityTokenAccessor = securityTokenAccessor;
using CertLib;
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace KeyGenSigning
{
class Program
{
static void Main(string[] args)
@daonhan
daonhan / cert.cs
Created January 25, 2021 11:25 — forked from yutopio/cert.cs
Certificate generation with BouncyCastle C#
using Org.BouncyCastle.Asn1.Pkcs;
using Org.BouncyCastle.Asn1.Sec;
using Org.BouncyCastle.Asn1.X509;
using Org.BouncyCastle.Asn1.X9;
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Generators;
using Org.BouncyCastle.Crypto.Operators;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.Math;
using Org.BouncyCastle.Security;
@daonhan
daonhan / Example.html
Created January 18, 2021 02:04 — forked from Danielku15/Example.html
A MediaTypeFormatter for WebApi for multipart/form-data including file uploads
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>File Upload example</title>
<link href="/Content/bootstrap.css" rel="stylesheet" />
</head>
<body>
<form action="api/Upload" method="post">
<div class="form-group">
@daonhan
daonhan / CreateCertificateAuthorityCert.bat
Created January 8, 2021 04:01 — forked from andrewabest/CreateCertificateAuthorityCert.bat
Create a cert authority and client certificate for development using makecert.exe
:: Courtesy of http://www.digitallycreated.net/Blog/38/using-makecert-to-create-certificates-for-development
:: To see what certificates you currently have on your PC, open MMC (Run->mmc.exe), click "File->Add/Remove Snap-in", select Certificates from the left list, click "Add". Select "My user account", which will mean the snapin will show certificates that are stored specifically for your Windows user account. Select Certificates from the list again and "Add" it, then this time select "Computer account". This snapin will show certificates belonging to the machine specifically, and will apply across all accounts. Press Finish, then OK. I suggest you Save this MMC arrangement, so you can get back to it more easily in the future (File->Save).
:: Expand "Certificates (Local Computer)\Trusted Root Certification Authorities\Certificates". This folder shows you all the Certificate Authorities that your computer trusts.
:: So now we need to create our own Certificate Authority certificate. Open the Visual Studio
@daonhan
daonhan / a_openssl_command_playground.md
Created January 6, 2021 08:27 — forked from rustymagnet3000/a_openssl_command_playground.md
openSSL verify certificates s_client capath public keys Print Certificates c_rehash key pairs

OpenSSL Playground

Certificates

Print Certificate ( crt file )

openssl x509 -in stackexchangecom.crt -text -noout

Print Certificate ( pem file )

openssl x509 -in cert.pem -text -noout

Print Certificate ( cer file )

openssl x509 -inform der -in foobar.cer -noout -text

Read part of Certificate
@daonhan
daonhan / DynamicHelper.cs
Created October 29, 2020 15:43 — forked from martinnormark/DynamicHelper.cs
C# Dynamic extension methods for serializing to XML
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Xml;
using System.Xml.Linq;
/// <summary>
/// Extension methods for the dynamic object.
/// </summary>
@daonhan
daonhan / file-uploader.component.html
Created September 1, 2020 04:55 — forked from stuartaccent/file-uploader.component.html
Angular 7 file uploader with queue and progress using HttpClient, example https://stackblitz.com/edit/angular-7-file-upload-queue
<div class="row">
<div class="col-md-3">
<h3>Select files</h3>
<input type="file" #fileInput multiple (change)="addToQueue()" />
</div>
<div class="col-md-9">
<h3>Upload queue</h3>
<table class="table-headed table-striped">
package auth
import (
"context"
"net/http"
"strings"
"google.golang.org/grpc/metadata"
"github.com/andela/micro-api-gateway/pb/authorization"