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