minor optimizations
This commit is contained in:
@@ -10,7 +10,7 @@ namespace Pilz.Cryptography
|
||||
{
|
||||
public class SimpleStringCrypter : ICrypter
|
||||
{
|
||||
private TripleDES TripleDes;
|
||||
private readonly TripleDES TripleDes;
|
||||
public Encoding TextEncoding { get; private set; } = Encoding.Default;
|
||||
|
||||
public SimpleStringCrypter() : this(string.Empty)
|
||||
@@ -32,8 +32,8 @@ namespace Pilz.Cryptography
|
||||
private byte[] TruncateHash(string key, int length)
|
||||
{
|
||||
SHA1 sha1CryptoServiceProvider = SHA1.Create();
|
||||
byte[] bytes = TextEncoding.GetBytes(key);
|
||||
byte[] array = sha1CryptoServiceProvider.ComputeHash(bytes);
|
||||
var bytes = TextEncoding.GetBytes(key);
|
||||
var array = sha1CryptoServiceProvider.ComputeHash(bytes);
|
||||
|
||||
var output = new byte[length];
|
||||
var lowerLength = Math.Min(array.Length, output.Length);
|
||||
@@ -46,9 +46,9 @@ namespace Pilz.Cryptography
|
||||
|
||||
private string EncryptData(string plaintext)
|
||||
{
|
||||
byte[] bytes = TextEncoding.GetBytes(plaintext);
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
CryptoStream cryptoStream = new CryptoStream(memoryStream, TripleDes.CreateEncryptor(), CryptoStreamMode.Write);
|
||||
var bytes = TextEncoding.GetBytes(plaintext);
|
||||
using var memoryStream = new MemoryStream();
|
||||
using var cryptoStream = new CryptoStream(memoryStream, TripleDes.CreateEncryptor(), CryptoStreamMode.Write);
|
||||
cryptoStream.Write(bytes, 0, bytes.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
return Convert.ToBase64String(memoryStream.ToArray());
|
||||
@@ -56,9 +56,9 @@ namespace Pilz.Cryptography
|
||||
|
||||
private string DecryptData(string encryptedtext)
|
||||
{
|
||||
byte[] array = Convert.FromBase64String(encryptedtext);
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
CryptoStream cryptoStream = new CryptoStream(memoryStream, TripleDes.CreateDecryptor(), CryptoStreamMode.Write);
|
||||
var array = Convert.FromBase64String(encryptedtext);
|
||||
using var memoryStream = new MemoryStream();
|
||||
using var cryptoStream = new CryptoStream(memoryStream, TripleDes.CreateDecryptor(), CryptoStreamMode.Write);
|
||||
cryptoStream.Write(array, 0, array.Length);
|
||||
cryptoStream.FlushFinalBlock();
|
||||
return TextEncoding.GetString(memoryStream.ToArray());
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
|
||||
<Version>2.5.1</Version>
|
||||
<Version>2.5.2</Version>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Pilz.UI.Telerik.SymbolFactory\Pilz.UI.Telerik.SymbolFactory.csproj" />
|
||||
|
||||
Reference in New Issue
Block a user