diff options
| author | LogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com> | 2019-02-18 00:31:03 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-02-18 00:31:03 -0800 |
| commit | 9f3aa2cead95ec0a66a518919c179eea4cad5d9c (patch) | |
| tree | a6001bd74f924418df121c5098ca275a9454c931 /Emby.Server.Implementations/Cryptography/CryptographyProvider.cs | |
| parent | d8e6808d77eb70025b4a26538a1deb814cbe2831 (diff) | |
Apply suggestions from code review
Adding minor stylistic suggestions from Bond-009
Co-Authored-By: LogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com>
Diffstat (limited to 'Emby.Server.Implementations/Cryptography/CryptographyProvider.cs')
| -rw-r--r-- | Emby.Server.Implementations/Cryptography/CryptographyProvider.cs | 41 |
1 files changed, 24 insertions, 17 deletions
diff --git a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs b/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs index 7817989e7..436443f06 100644 --- a/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs +++ b/Emby.Server.Implementations/Cryptography/CryptographyProvider.cs @@ -72,7 +72,7 @@ namespace Emby.Server.Implementations.Cryptography }
private byte[] PBKDF2(string method, byte[] bytes, byte[] salt, int iterations)
- { + {
using (var r = new Rfc2898DeriveBytes(bytes, salt, iterations, new HashAlgorithmName(method)))
{
return r.GetBytes(32);
@@ -107,9 +107,9 @@ namespace Emby.Server.Implementations.Cryptography }
else
{
- throw new CryptographicException(String.Format("Requested hash method is not supported: {0}", HashMethod));
+ throw new CryptographicException($"Requested hash method is not supported: {HashMethod}"));
}
- } + }
public byte[] ComputeHashWithDefaultMethod(byte[] bytes, byte[] salt)
{
@@ -117,25 +117,32 @@ namespace Emby.Server.Implementations.Cryptography }
public byte[] ComputeHash(PasswordHash hash)
- { - int iterations = defaultiterations; - if (!hash.Parameters.ContainsKey("iterations")) - { - hash.Parameters.Add("iterations", defaultiterations.ToString()); - } - else - { - try { iterations = int.Parse(hash.Parameters["iterations"]); } - catch (Exception e) { iterations = defaultiterations; throw new Exception($"Couldn't successfully parse iterations value from string:{hash.Parameters["iterations"]}", e); } + {
+ int iterations = defaultiterations;
+ if (!hash.Parameters.ContainsKey("iterations"))
+ {
+ hash.Parameters.Add("iterations", defaultiterations.ToString(CultureInfo.InvariantCulture));
+ }
+ else
+ {
+ try
+ {
+ iterations = int.Parse(hash.Parameters["iterations"]);
+ }
+ catch (Exception e)
+ {
+ iterations = defaultiterations;
+ throw new Exception($"Couldn't successfully parse iterations value from string:{hash.Parameters["iterations"]}", e);
+ }
}
- return PBKDF2(hash.Id, hash.HashBytes, hash.SaltBytes,iterations);
- } - + return PBKDF2(hash.Id, hash.HashBytes, hash.SaltBytes, iterations);
+ }
+
public byte[] GenerateSalt()
{
byte[] salt = new byte[64];
rng.GetBytes(salt);
return salt;
- } + }
}
}
|
