Skip to content

Instantly share code, notes, and snippets.

@brenoferreira
Created June 8, 2012 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save brenoferreira/2897946 to your computer and use it in GitHub Desktop.
Save brenoferreira/2897946 to your computer and use it in GitHub Desktop.
Private methods
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
namespace License
{
public class LicenseServiceImpl
{
public String GenerateLicense(String secret)
{
var hashBytes = this.ComputeSecretHash(secret);
return Convert.ToBase64String(hashBytes);
}
public Boolean ValidateLicense(String license, String secret)
{
var hashBytes = this.ComputeSecretHash(secret);
var hashBase64Str = Convert.ToBase64String(hashBytes);
return license == hashBase64Str;
}
private byte[] ComputeSecretHash(String secret)
{
SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider();
var secretBytes = Encoding.UTF8.GetBytes(secret);
var hashBytes = sha1.ComputeHash(secretBytes);
return hashBytes;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment