Skip to content

Instantly share code, notes, and snippets.

@njmube
njmube / RSA.cs
Last active August 29, 2015 14:23 — forked from angelobelchior/RSA.cs
using System;
using System.Security.Cryptography;
namespace Cryptography
{
public class RSA
{
public static string Encrypt(string text, string key)
{
Throw.IfIsNullOrEmpty(text);
public class OAuthTokenUtility {
private readonly RSACryptoServiceProvider _PublicProvider;
private readonly RSACryptoServiceProvider _PrivateProvider;
public OAuthTokenUtility(X509Certificate2 certificate) {
_PublicProvider = (RSACryptoServiceProvider)certificate.PublicKey.Key;
_PrivateProvider = (RSACryptoServiceProvider)Certificate.PrivateKey;
}
public string Token(string username, double numberOfMinutesToExpireIn, IEnumerable<string> tokens) {
@njmube
njmube / Program.cs
Last active August 29, 2015 14:23 — forked from mohnish82/Program.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace DigitalSigning
{
using System;
using System.Linq;
using APSP.Form.Model;
using NHibernateRepository;
using NUnit.Framework;
using System.Collections.Generic;
using System.IO;
using System.Security.Cryptography;
using System.Text;
namespace APSPTest
namespace EncryptionWithCertificate
{
using System;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Text;
class Program
{
//// makecert -pe MyCryptCert.cer -ss my -n "CN=Frans2" -sky exchange -r
using System;
using System.IO;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace CryptoPlayground.StrongNameKeyManagement
{
public class StrongNameKeyManager
{
public StrongNameKeyManager(string containerName, bool machineScope = true)
@njmube
njmube / RSADigest.cs
Last active August 29, 2015 14:23 — forked from imzjy/RSADigest.cs
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.IO;
namespace ConsoleTester
// signature
var signature = headerEncoded + "." + claimEncoded;
var signatureBytes = Encoding.UTF8.GetBytes(signature);
var certificate = new X509Certificate2(privateKey, privateKeyPassword);
// sign signature using SHA256 with RSA
var rsa = (RSACryptoServiceProvider)certificate.PrivateKey;
// As of .NET 3.5 SP1 the CSP instance works with a provider of type PROV_RSA_AES
@njmube
njmube / opensslkey.cs
Last active November 10, 2022 14:17 — forked from stormwild/opensslkey.cs
//**********************************************************************************
//
//OpenSSLKey
// .NET 2.0 OpenSSL Public & Private Key Parser
//
// Copyright (C) 2008 JavaScience Consulting
//
//***********************************************************************************
//
// opensslkey.cs
@njmube
njmube / Program.cs
Last active August 29, 2015 14:23 — forked from fmoliveira/Program.cs
using System;
using System.Security.Cryptography;
namespace SomeProgram
{
static class Program
{
static void Main()
{
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(KEY_SIZE))