Skip to content

Commit

Permalink
Fixed obsolete crypto warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
openbullet committed Mar 20, 2022
1 parent 691e52e commit 77bf8d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 52 deletions.
20 changes: 10 additions & 10 deletions RuriLib/Functions/Crypto/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public static byte[] MD4(byte[] input)
/// <returns>The MD5 digest.</returns>
public static byte[] MD5(byte[] input)
{
using MD5 md5 = System.Security.Cryptography.MD5.Create();
using var md5 = System.Security.Cryptography.MD5.Create();
return md5.ComputeHash(input);
}

Expand All @@ -155,7 +155,7 @@ public static byte[] MD5(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACMD5(byte[] input, byte[] key)
{
using HMACMD5 hmac = new HMACMD5(key);
using var hmac = new HMACMD5(key);
return hmac.ComputeHash(input);
}

Expand All @@ -166,7 +166,7 @@ public static byte[] HMACMD5(byte[] input, byte[] key)
/// <returns>The SHA-1 digest.</returns>
public static byte[] SHA1(byte[] input)
{
using SHA1Managed sha1 = new SHA1Managed();
using var sha1 = System.Security.Cryptography.SHA1.Create();
return sha1.ComputeHash(input);
}

Expand All @@ -178,7 +178,7 @@ public static byte[] SHA1(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACSHA1(byte[] input, byte[] key)
{
using HMACSHA1 hmac = new HMACSHA1(key);
using var hmac = new HMACSHA1(key);
return hmac.ComputeHash(input);
}

Expand All @@ -189,7 +189,7 @@ public static byte[] HMACSHA1(byte[] input, byte[] key)
/// <returns>The SHA-256 digest.</returns>
public static byte[] SHA256(byte[] input)
{
using SHA256Managed sha256 = new SHA256Managed();
using var sha256 = System.Security.Cryptography.SHA256.Create();
return sha256.ComputeHash(input);
}

Expand All @@ -209,7 +209,7 @@ public static byte[] SHA256(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACSHA256(byte[] input, byte[] key)
{
using HMACSHA256 hmac = new HMACSHA256(key);
using var hmac = new HMACSHA256(key);
return hmac.ComputeHash(input);
}

Expand All @@ -220,7 +220,7 @@ public static byte[] HMACSHA256(byte[] input, byte[] key)
/// <returns>The SHA-384 digest.</returns>
public static byte[] SHA384(byte[] input)
{
using SHA384Managed sha384 = new SHA384Managed();
using var sha384 = System.Security.Cryptography.SHA384.Create();
return sha384.ComputeHash(input);
}

Expand All @@ -232,7 +232,7 @@ public static byte[] SHA384(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACSHA384(byte[] input, byte[] key)
{
using HMACSHA384 hmac = new HMACSHA384(key);
using var hmac = new HMACSHA384(key);
return hmac.ComputeHash(input);
}

Expand All @@ -243,7 +243,7 @@ public static byte[] HMACSHA384(byte[] input, byte[] key)
/// <returns>The SHA-512 digest.</returns>
public static byte[] SHA512(byte[] input)
{
using SHA512Managed sha512 = new SHA512Managed();
using var sha512 = System.Security.Cryptography.SHA512.Create();
return sha512.ComputeHash(input);
}

Expand All @@ -255,7 +255,7 @@ public static byte[] SHA512(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACSHA512(byte[] input, byte[] key)
{
using HMACSHA512 hmac = new HMACSHA512(key);
using var hmac = new HMACSHA512(key);
return hmac.ComputeHash(input);
}

Expand Down
64 changes: 22 additions & 42 deletions RuriLib/Legacy/Functions/Crypto/Crypto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,8 @@ public static byte[] MD4(byte[] input)
/// <returns>The MD5 digest.</returns>
public static byte[] MD5(byte[] input)
{
using (MD5 md5 = System.Security.Cryptography.MD5.Create())
{
return md5.ComputeHash(input);
}
using var md5 = System.Security.Cryptography.MD5.Create();
return md5.ComputeHash(input);
}

/// <summary>
Expand All @@ -106,10 +104,8 @@ public static byte[] MD5(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACMD5(byte[] input, byte[] key)
{
using (HMACMD5 hmac = new HMACMD5(key))
{
return hmac.ComputeHash(input);
}
using var hmac = new HMACMD5(key);
return hmac.ComputeHash(input);
}

/// <summary>
Expand All @@ -119,10 +115,8 @@ public static byte[] HMACMD5(byte[] input, byte[] key)
/// <returns>The SHA-1 digest.</returns>
public static byte[] SHA1(byte[] input)
{
using (SHA1Managed sha1 = new SHA1Managed())
{
return sha1.ComputeHash(input);
}
using var sha1 = System.Security.Cryptography.SHA1.Create();
return sha1.ComputeHash(input);
}

/// <summary>
Expand All @@ -133,10 +127,8 @@ public static byte[] SHA1(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACSHA1(byte[] input, byte[] key)
{
using (HMACSHA1 hmac = new HMACSHA1(key))
{
return hmac.ComputeHash(input);
}
using var hmac = new HMACSHA1(key);
return hmac.ComputeHash(input);
}

/// <summary>
Expand All @@ -146,10 +138,8 @@ public static byte[] HMACSHA1(byte[] input, byte[] key)
/// <returns>The SHA-256 digest.</returns>
public static byte[] SHA256(byte[] input)
{
using (SHA256Managed sha256 = new SHA256Managed())
{
return sha256.ComputeHash(input);
}
using var sha256 = System.Security.Cryptography.SHA256.Create();
return sha256.ComputeHash(input);
}

/// <summary>
Expand All @@ -160,10 +150,8 @@ public static byte[] SHA256(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACSHA256(byte[] input, byte[] key)
{
using (HMACSHA256 hmac = new HMACSHA256(key))
{
return hmac.ComputeHash(input);
}
using var hmac = new HMACSHA256(key);
return hmac.ComputeHash(input);
}

/// <summary>
Expand All @@ -173,10 +161,8 @@ public static byte[] HMACSHA256(byte[] input, byte[] key)
/// <returns>The SHA-384 digest.</returns>
public static byte[] SHA384(byte[] input)
{
using (SHA384Managed sha384 = new SHA384Managed())
{
return sha384.ComputeHash(input);
}
using var sha384 = System.Security.Cryptography.SHA384.Create();
return sha384.ComputeHash(input);
}

/// <summary>
Expand All @@ -187,10 +173,8 @@ public static byte[] SHA384(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACSHA384(byte[] input, byte[] key)
{
using (HMACSHA384 hmac = new HMACSHA384(key))
{
return hmac.ComputeHash(input);
}
using var hmac = new HMACSHA384(key);
return hmac.ComputeHash(input);
}

/// <summary>
Expand All @@ -200,10 +184,8 @@ public static byte[] HMACSHA384(byte[] input, byte[] key)
/// <returns>The SHA-512 digest.</returns>
public static byte[] SHA512(byte[] input)
{
using (SHA512Managed sha512 = new SHA512Managed())
{
return sha512.ComputeHash(input);
}
using var sha512 = System.Security.Cryptography.SHA512.Create();
return sha512.ComputeHash(input);
}

/// <summary>
Expand All @@ -214,10 +196,8 @@ public static byte[] SHA512(byte[] input)
/// <returns>The HMAC signature.</returns>
public static byte[] HMACSHA512(byte[] input, byte[] key)
{
using (HMACSHA512 hmac = new HMACSHA512(key))
{
return hmac.ComputeHash(input);
}
using var hmac = new HMACSHA512(key);
return hmac.ComputeHash(input);
}

/// <summary>
Expand All @@ -228,7 +208,7 @@ public static byte[] HMACSHA512(byte[] input, byte[] key)
public static string ToHex(this byte[] bytes)
{
var sb = new StringBuilder(bytes.Length * 2);
foreach (byte b in bytes)
foreach (var b in bytes)
sb.Append(b.ToString("X2"));
return sb.ToString();
}
Expand All @@ -243,7 +223,7 @@ public static byte[] FromHex(this string input)
var resultantArray = new byte[input.Length / 2];
for (var i = 0; i < resultantArray.Length; i++)
{
resultantArray[i] = System.Convert.ToByte(input.Substring(i * 2, 2), 16);
resultantArray[i] = Convert.ToByte(input.Substring(i * 2, 2), 16);
}
return resultantArray;
}
Expand Down

0 comments on commit 77bf8d9

Please sign in to comment.