Donald's Bacon Bytes

bytes of information as tasty as bacon

Honey BBQ Double Smoked Bacon

Topic: Cooking | Tags:

Aug
21
2016

honeybbqbacon_intro
A couple months ago I went to a bacon festival and had chunks of bacon coated in bbq sauce. Ever since then I’ve been wanting to do some kind of dish similar to that. I finally did and it turned out amazing. As good as expected …

Read full story



Memphis Dust Meat Rub

Topic: Cooking |

Aug
14
2016

MemphisDust
One of my favorite sites to read is AmazingRibs.com. Yes, you are on my blog and I’m telling you about a different site. I might even have some similar content but I’ll have variations and original stuff as well …

Read full story



Create JWT with a Private RSA Key

Topic: Development | Tags: ,

Aug
11
2016

Recently I ran into a challenge at work and that I had hard time figuring out how to solve. We have an authenticate server written in NodeJS. It signs a user into our application and creates a JWT. This application signs the JWT with a PEM file which ONLY has a Private RSA Key. Our C# API can use the corresponding certificate file (.cer) to validate the token when it is passed in each API call.

This has been working great. For reasons I’m not going to get into here, we had to come up with a way to create a token from our Asp.Net admin that would allow someone to login as a specific user without logging in. We are doing this for a demo type of user account. The challenge was that I couldn’t find any good examples that would allow me to create the JWT using only the PEM file. I found hints here and there but nothing exact.

The solution I came up with was to use a combination of Bouncy Castle and Jose JWT. I used Bouncy Castle to create the signing key and then Jose JWT to encode the token.

public static string CreateToken(List<Claim> claims, string certificateName, string rootFolder, string certificateFolder = "Certificates")
 { 
 string path = Path.Combine(rootFolder, certificateFolder, certificateName);
 string pemString = File.ReadAllText(path);
 string jwt = string.Empty;
 AsymmetricCipherKeyPair keyPair;

 using (StreamReader sr = new StreamReader(path))
 {
 PemReader pr = new PemReader(sr);
 keyPair = (AsymmetricCipherKeyPair)pr.ReadObject();
 } 
 
 RSAParameters rsaParams = DotNetUtilities.ToRSAParameters((RsaPrivateCrtKeyParameters)keyPair.Private);

 using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
 {
 rsa.ImportParameters(rsaParams);
 Dictionary<string, object> payload = claims.ToDictionary(k => k.Type, v => (object)v.Value);
 jwt = Jose.JWT.Encode(payload, rsa, Jose.JwsAlgorithm.RS256);
 }

 return jwt;
 }

As you can see, this is a someone generic method that takes in the path to the certificate along with the claims and then creates the JWT out of that information.

Anyway, I hope this can help others.

If you have other suggestions, I’d love to hear them in the comments.



Wet Cured Bacon

Topic: Cooking | Tags:

Aug
07
2016

SlicedWetCuredBacon_intro
Man do I love some good bacon. I’ve been dry curing bacon for a few years now and decided I wanted to try doing a wet cure. I came across a great thread about this over at SmokingMeatForums.com and decided to give it a try.

Wow! It was amazing!! …

Read full story



London Broil Skewers

Topic: Cooking |

Jul
31
2016

introImage
I’m a big fan of beef but it can be expensive. So, I usually look for sales and then figure out how to use that meat to make a delicious meal. Recently there was a great sale on London Broil. It is a great piece of meat for grilling and it works well with marinade …

Read full story