-
-
Save juanplopes/2898005 to your computer and use it in GitHub Desktop.
Private methods
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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