Skip to content

Instantly share code, notes, and snippets.

View brainded's full-sized avatar

Adam Valverde brainded

View GitHub Profile
@brainded
brainded / WebhhookSigning.cs
Last active March 31, 2021 18:40
Virtuous Webhook Signature Verification
using System;
using System.Text;
using System.Security.Cryptography;
public static class WebhookUtility
{
public static bool IsVerified(string payload, string sharedSecret, string virtuousSignature)
{
byte[] valueByteArray = Encoding.UTF8.GetBytes(payload);
byte[] secretByteArray = Encoding.UTF8.GetBytes(sharedSecret);
@brainded
brainded / Program.cs
Created January 16, 2018 23:03
Mode White-Label Embed Token Security
using System;
using System.Globalization;
using System.Text.RegularExpressions;
using System.Text;
using System.Security.Cryptography;
public class Program
{
public static void Main()
{
@brainded
brainded / hmac.php
Created July 20, 2017 21:26
Virtuous Hmac in PHP
<?php
function getHmacToken($applicationKey, $requestHttpMethod, $requestUrl)
{
$privateKey = "VIRTUOUS_API_KEY";
$nonce = uniqid();
$timestamp = (string)time();
$toBeHashed = strtolower($applicationKey . urlencode($requestUrl) . $requestHttpMethod . $nonce . $timestamp);
$hmac = getHashedUrl($toBeHashed, $privateKey);
$authorization = "Hmac " . $applicationKey . ":" . $hmac . ":" . $nonce . ":" . $timestamp;

Keybase proof

I hereby claim:

  • I am brainded on github.
  • I am brainded (https://keybase.io/brainded) on keybase.
  • I have a public key ASAiGbLhWvuZ1MCQwtqngpHc1GMEwf34ogsl4NrfcKpGGQo

To claim this, I am signing this object:

@brainded
brainded / AsyncExtensions.cs
Created June 19, 2015 23:42
Handy Extension class that allows Async execution synchronously.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace BobsBurgers
{
internal static class AsyncExtensions
@brainded
brainded / BobsBurgersController.cs
Last active August 29, 2015 14:06
Utilize Output Cache with User Identity. Found on StackOverflow: http://stackoverflow.com/questions/17187736/output-cache-per-user
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TwitterPoc.Services;
namespace BobsBurgers.Controllers
{
@brainded
brainded / Kudu.json
Last active August 29, 2015 14:05
Kudu Deployment Json
{
"id": "32434k234jlk234l2k3j4j234l",
"status": "success",
"authorEmail": "[email protected]",
"author": "author",
"deployer": "GitHub",
"message": "something something darkside",
"progress": "",
"startTime": "2014-08-15T23:17:00.7435764Z",
"endTime": "2014-08-15T23:17:29.0472028Z",
@brainded
brainded / BobsBurgersConfiguration.cs
Created July 21, 2014 06:05
Example of a Custom Configuration Section. Can be used in conjunction with Config Transforms to provide different custom configuration per build/environment.
using System;
using System.Configuration;
namespace Example.Configuration
{
internal class BobsBurgersConfiguration : ConfigurationSection
{
/// <summary>
/// The BobsBurgers ConfigurationSection name.
/// </summary>
@brainded
brainded / JSController.js
Created June 20, 2014 23:53
ValidateAntiForgeryTokenAttribute for WebApi and how to use it.
var authorizationToken = $("#antiforgerytoken").val();
$.ajax({
type:"POST",
beforeSend: function (request) {
request.setRequestHeader("RequestVerificationToken", authorizationToken);
},
url: "entities",
data: {
Something: "something"
@brainded
brainded / ConditionallyRequireHttps.cs
Last active August 29, 2015 13:58
Conditionally Require Https Attribute that allows a controller or controller action to force Https unless certain conditions are met to cancel the forward.
namespace MvcEssentials
{
using System;
using System.Collections.Specialized;
using System.Configuration;
using System.Web.Mvc;
/// <summary>
/// Conditionally Require Https Attribute
/// </summary>