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