Skip to content

Instantly share code, notes, and snippets.

@badcommandorfilename
badcommandorfilename / RuntimeCast.cs
Created June 29, 2018 00:57
C# Runtime type Cast and CastEnumerable
static IEnumerable CastEnumerable(IEnumerable<object> input, Type t)
{
foreach(var o in input)
{
yield return Cast(o, t);
}
}
static object Cast(object obj, Type t)
@badcommandorfilename
badcommandorfilename / hide-sidebar.html
Created February 25, 2019 01:50
CSS only hide sidebar or navbar toggle
<style>
#sidebar {
width: 250px;
}
#hide-sidebar:checked ~ #sidebar {
width: 0;
display: none;
}
@badcommandorfilename
badcommandorfilename / ManagedAuthenticatedEncryptor
Created June 12, 2019 07:09
Standalone (mostly) SP800_108_CTR_HMACSHA512 Key Derivation Function for ASPNetCore cookie sharing
///This is a Frankenstein class that can extract the AES key from a KDK as described in:
/// https://docs.microsoft.com/en-us/aspnet/core/security/data-protection/implementation/subkeyderivation?view=aspnetcore-2.2
///With a bit of luck, this should let an ASP.NET app decrypt cookies generated by an ASPNETCore app
///Still consult https://docs.microsoft.com/en-us/aspnet/core/security/cookie-sharing?view=aspnetcore-2.2 to share cookies
///Credit for most of the code is from various parts of https://github.com/aspnet/AspNetCore/tree/master/src/DataProtection/DataProtection/src
public unsafe class CookieDataProtector : IDataProtector
{
readonly string _base64MasterKey;