-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
49 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
|
||
namespace KeySmith.Internals.Locks | ||
{ | ||
class IdentifierGenerator : IDisposable | ||
{ | ||
private static readonly char[] _chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-_".ToCharArray(); | ||
|
||
private readonly RNGCryptoServiceProvider _rngCryptoServiceProvider; | ||
|
||
public IdentifierGenerator() | ||
{ | ||
_rngCryptoServiceProvider = new RNGCryptoServiceProvider(); | ||
} | ||
|
||
public void Dispose() => _rngCryptoServiceProvider?.Dispose(); | ||
|
||
public string GetUniqueKey(int size) | ||
{ | ||
var data = new byte[size]; | ||
_rngCryptoServiceProvider.GetBytes(data); | ||
var result = new StringBuilder(size); | ||
foreach (var b in data) | ||
{ | ||
result.Append(_chars[b % _chars.Length]); | ||
} | ||
return result.ToString(); | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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