-
Notifications
You must be signed in to change notification settings - Fork 8
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
30 changed files
with
461 additions
and
206 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,29 @@ | ||
// * Summary * | ||
|
||
BenchmarkDotNet=v0.12.1, OS=Windows 10.0.18363.1016 (1909/November2018Update/19H2) | ||
AMD Ryzen 7 2700X, 1 CPU, 16 logical and 8 physical cores | ||
.NET Core SDK=5.0.100-preview.7.20366.6 | ||
[Host] : .NET Core 3.1.6 (CoreCLR 4.700.20.26901, CoreFX 4.700.20.31603), X64 RyuJIT | ||
DefaultJob : .NET Core 3.1.6 (CoreCLR 4.700.20.26901, CoreFX 4.700.20.31603), X64 RyuJIT | ||
BenchmarkDotNet v0.13.11, Windows 11 (10.0.22621.2861/22H2/2022Update/SunValley2) | ||
AMD Ryzen 5 5600X, 1 CPU, 12 logical and 6 physical cores | ||
.NET SDK 8.0.100 | ||
[Host] : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2 | ||
DefaultJob : .NET 8.0.0 (8.0.23.53103), X64 RyuJIT AVX2 | ||
|
||
| Method | Mean | Error | StdDev | | ||
|-------------------- |---------:|---------:|---------:| | ||
| RandomIntNoBuffer | 80.37 ns | 1.498 ns | 1.251 ns | | ||
| RandomIntWithBuffer | 60.88 ns | 1.064 ns | 0.995 ns | | ||
|
||
| Method | Mean | Error | StdDev | | ||
|---------------- |--------------:|-----------:|-----------:| | ||
| AesEncrypt | 11,780.431 us | 26.9828 us | 25.2397 us | | ||
| AesDecrypt | 23,168.337 us | 52.8699 us | 46.8678 us | | ||
| AesEncryptQuick | 3.837 us | 0.0280 us | 0.0248 us | | ||
| AesDecryptQuick | 4.181 us | 0.0331 us | 0.0310 us | | ||
|
||
// * Hints * | ||
Outliers | ||
CryptoRandomBanchmarks.RandomIntNoBuffer: Default -> 3 outliers were removed (88.08 ns..91.41 ns) | ||
EncryptionBenchmark.AesDecrypt: Default -> 1 outlier was removed (23.32 ms) | ||
EncryptionBenchmark.AesEncryptQuick: Default -> 1 outlier was removed (3.92 us) | ||
|
||
// * Legends * | ||
Mean : Arithmetic mean of all measurements | ||
Error : Half of 99.9% confidence interval | ||
StdDev : Standard deviation of all measurements | ||
1 us : 1 Microsecond (0.000001 sec) | ||
|
||
- Mean : Arithmetic mean of all measurements | ||
- Error : Half of 99.9% confidence interval | ||
- StdDev : Standard deviation of all measurements | ||
- 1 ns : 1 Nanosecond (0.000000001 sec) | ||
// ***** BenchmarkRunner: End ***** | ||
Run time: 00:01:17 (77.51 sec), executed benchmarks: 4 |
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
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,44 @@ | ||
namespace EasyCrypto; | ||
|
||
/// <summary> | ||
/// Faster AES-256 to be used only with generated keys, not passwords, use <see cref="QuickEncryptionKey"/> | ||
/// </summary> | ||
public class QuickEncryption | ||
{ | ||
private readonly QuickEncryptionKey _key; | ||
|
||
public QuickEncryption(QuickEncryptionKey key) | ||
{ | ||
_key = key; | ||
} | ||
|
||
public byte[] Encrypt(byte[] plainTextData) => Encrypt(plainTextData, _key); | ||
|
||
public string Encrypt(string plainText) => Encrypt(plainText, _key); | ||
|
||
public byte[] Decrypt(byte[] data) => Decrypt(data, _key); | ||
|
||
public string Decrypt(string encryptedData) => Decrypt(encryptedData, _key); | ||
|
||
public static string Encrypt(string plainText, QuickEncryptionKey key) | ||
{ | ||
byte[] value = Encrypt(Encoding.UTF8.GetBytes(plainText), key); | ||
return Convert.ToBase64String(value); | ||
} | ||
|
||
public static string Decrypt(string encryptedData, QuickEncryptionKey key) | ||
{ | ||
byte[] data = Decrypt(Convert.FromBase64String(encryptedData), key); | ||
return Encoding.UTF8.GetString(data); | ||
} | ||
|
||
public static byte[] Encrypt(byte[] plainTextData, QuickEncryptionKey key) | ||
{ | ||
return AesEncryption.EncryptAndEmbedIv(plainTextData, key.Key); | ||
} | ||
|
||
public static byte[] Decrypt(byte[] data, QuickEncryptionKey key) | ||
{ | ||
return AesEncryption.DecryptWithEmbeddedIv(data, key.Key); | ||
} | ||
} |
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,51 @@ | ||
namespace EasyCrypto; | ||
|
||
/// <summary> | ||
/// Key to be used with <see cref="QuickEncryption"/> | ||
/// </summary> | ||
public class QuickEncryptionKey | ||
{ | ||
internal string Value { get; } | ||
internal byte[] Key { get; } | ||
|
||
private const int KeyLength = 32; | ||
|
||
private QuickEncryptionKey(string value) | ||
{ | ||
Value = value; | ||
SHA256 sha = SHA256.Create(); | ||
Key = sha.ComputeHash(Encoding.UTF8.GetBytes(value)); | ||
} | ||
|
||
/// <summary> | ||
/// Creates new randomly generated key | ||
/// </summary> | ||
/// <returns></returns> | ||
public static QuickEncryptionKey CreateNew() | ||
{ | ||
string token = TokenGenerator.Default.GenerateToken(KeyLength); | ||
return new QuickEncryptionKey(token); | ||
} | ||
|
||
/// <summary> | ||
/// Parses key from string | ||
/// </summary> | ||
/// <param name="value">Value to parse</param> | ||
/// <returns><see cref="QuickEncryptionKey"/></returns> | ||
/// <exception cref="ArgumentException">Throw in case of not valid argument</exception> | ||
public static QuickEncryptionKey Parse(string value) | ||
{ | ||
if (value.Length != KeyLength) | ||
{ | ||
throw new ArgumentException("Not valid value"); | ||
} | ||
|
||
return new QuickEncryptionKey(value); | ||
} | ||
|
||
/// <summary> | ||
/// Returns key represented as string | ||
/// </summary> | ||
/// <returns>String value of the key</returns> | ||
public override string ToString() => Value; | ||
} |
14 changes: 0 additions & 14 deletions
14
...Artifacts/results/EasyCrypto.Benchmarks.CryptoRandomBenchmarks-report-github.md
This file was deleted.
Oops, something went wrong.
3 changes: 0 additions & 3 deletions
3
...BenchmarkDotNet.Artifacts/results/EasyCrypto.Benchmarks.CryptoRandomBenchmarks-report.csv
This file was deleted.
Oops, something went wrong.
31 changes: 0 additions & 31 deletions
31
...enchmarkDotNet.Artifacts/results/EasyCrypto.Benchmarks.CryptoRandomBenchmarks-report.html
This file was deleted.
Oops, something went wrong.
15 changes: 0 additions & 15 deletions
15
...lts/EasyCrypto.Benchmarks.PasswordHasherAndValidatorBenchmarks-report-github.md
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
...t.Artifacts/results/EasyCrypto.Benchmarks.PasswordHasherAndValidatorBenchmarks-report.csv
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.