![]() |
VOOZH | about |
dotnet add package ZidUtilities.CommonCode --version 1.0.5
NuGet\Install-Package ZidUtilities.CommonCode -Version 1.0.5
<PackageReference Include="ZidUtilities.CommonCode" Version="1.0.5" />
<PackageVersion Include="ZidUtilities.CommonCode" Version="1.0.5" />Directory.Packages.props
<PackageReference Include="ZidUtilities.CommonCode" />Project file
paket add ZidUtilities.CommonCode --version 1.0.5
#r "nuget: ZidUtilities.CommonCode, 1.0.5"
#:package ZidUtilities.CommonCode@1.0.5
#addin nuget:?package=ZidUtilities.CommonCode&version=1.0.5Install as a Cake Addin
#tool nuget:?package=ZidUtilities.CommonCode&version=1.0.5Install as a Cake Tool
Core utility library providing common functionality used across the ZidUtilities solution.
This is a core library with minimal external dependencies, designed to be lightweight and reusable.
.NET Framework 4.8
using ZidUtilities.CommonCode;
var crypter = new Crypter();
// Encrypt a string
string plainText = "Sensitive data that needs protection";
string encryptionKey = "MySecurePassword123";
string encrypted = crypter.Encrypt(plainText, encryptionKey);
Console.WriteLine($"Encrypted: {encrypted}");
// Decrypt the string
string decrypted = crypter.Decrypt(encrypted, encryptionKey);
Console.WriteLine($"Decrypted: {decrypted}");
var crypter = new Crypter();
// Using AES (default and recommended)
string aesEncrypted = crypter.Encrypt("Secret data", "key", Crypter.Algorithm.AES);
// Using Rijndael
string rijndaelEncrypted = crypter.Encrypt("Secret data", "key", Crypter.Algorithm.Rijndael);
// For legacy compatibility (not recommended for new applications)
string tripleDesEncrypted = crypter.Encrypt("Secret data", "key", Crypter.Algorithm.Triple_Des);
var crypter = new Crypter
{
SaltValue = "MyCustomSalt",
PasswordIterations = 100000, // NIST recommended
HashAlgorithm = "SHA256",
KeySize = 256,
UseModernKdf = true
};
string encrypted = crypter.Encrypt("High security data", "StrongPassword!");
string decrypted = crypter.Decrypt(encrypted, "StrongPassword!");
// If you need to decrypt data encrypted with old settings
var crypter = new Crypter();
crypter.SetLegacyValues(); // Uses SHA1, 2 iterations, 128-bit keys
string legacyDecrypted = crypter.Decrypt(oldEncryptedData, "OldPassword");
var crypter = new Crypter();
// Encrypt a file
int result = crypter.EncryptFile(
inputFile: @"C:\docs\confidential.pdf",
outputFile: @"C:\docs\confidential.pdf.encrypted",
encryptionKey: "FileProtectionKey2024"
);
if (result == 1)
{
Console.WriteLine("File encrypted successfully!");
// Decrypt the file
result = crypter.DecryptFile(
inputFile: @"C:\docs\confidential.pdf.encrypted",
outputFile: @"C:\docs\confidential_decrypted.pdf",
encryptionKey: "FileProtectionKey2024"
);
if (result == 1)
Console.WriteLine("File decrypted successfully!");
}
// MD5 Hash (use only for legacy compatibility)
string md5Hash = Crypter.GetMd5Sum("Hello World");
bool md5Valid = Crypter.VerifyMd5Sum("Hello World", md5Hash);
// SHA256 Hash (recommended for modern applications)
string sha256Hash = Crypter.GetSha256Sum("Hello World");
bool sha256Valid = Crypter.VerifySha256Sum("Hello World", sha256Hash);
// SHA512 Hash (maximum security)
string sha512Hash = Crypter.GetSha512Sum("Hello World");
bool sha512Valid = Crypter.VerifySha512Sum("Hello World", sha512Hash);
// File hashing
string fileHash = Crypter.GetSha256Sum(@"C:\docs\document.pdf");
Console.WriteLine($"File SHA256: {fileHash}");
using ZidUtilities.CommonCode;
var generator = new PasswordGenerator(length: 12);
// Add rules for password composition
generator.Rules.Add(new PasswordComponent
{
CompType = PasswordComponentType.UpperCase,
Quantity = 2
});
generator.Rules.Add(new PasswordComponent
{
CompType = PasswordComponentType.LowerCase,
Quantity = 6
});
generator.Rules.Add(new PasswordComponent
{
CompType = PasswordComponentType.Digit,
Quantity = 2
});
generator.Rules.Add(new PasswordComponent
{
CompType = PasswordComponentType.SpecialChar,
Quantity = 2
});
string password = generator.GetPassword();
Console.WriteLine($"Generated Password: {password}");
// Example output: "aB3dEf!2gH@i"
var generator = new PasswordGenerator(16);
generator.Rules.Add(new PasswordComponent { CompType = PasswordComponentType.UpperCase, Quantity = 3 });
generator.Rules.Add(new PasswordComponent { CompType = PasswordComponentType.LowerCase, Quantity = 8 });
generator.Rules.Add(new PasswordComponent { CompType = PasswordComponentType.Digit, Quantity = 3 });
generator.Rules.Add(new PasswordComponent { CompType = PasswordComponentType.SpecialChar, Quantity = 2 });
// Generate 10 unique passwords
for (int i = 0; i < 10; i++)
{
Console.WriteLine($"Password {i + 1}: {generator.GetPassword()}");
}
// Corporate password policy: 14 chars, 2 uppercase, 8 lowercase, 2 digits, 2 special
var corpGenerator = new PasswordGenerator(14);
corpGenerator.Rules.Add(new PasswordComponent { CompType = PasswordComponentType.UpperCase, Quantity = 2 });
corpGenerator.Rules.Add(new PasswordComponent { CompType = PasswordComponentType.LowerCase, Quantity = 8 });
corpGenerator.Rules.Add(new PasswordComponent { CompType = PasswordComponentType.Digit, Quantity = 2 });
corpGenerator.Rules.Add(new PasswordComponent { CompType = PasswordComponentType.SpecialChar, Quantity = 2 });
string corporatePassword = corpGenerator.GetPassword();
// If no rules are specified, the generator fills with random letters
var simpleGenerator = new PasswordGenerator(10);
string simplePassword = simpleGenerator.GetPassword();
// Output will be random letters (upper and lowercase)
The Check class provides various validation utilities for securing user input and validating data formats.
using ZidUtilities.CommonCode;
// Use Check class methods for validation
// (Specific examples depend on the methods available in Check.cs)
The Extensions class provides helpful extension methods for common .NET types including string manipulation, collection operations, and data transformations.
using ZidUtilities.CommonCode;
// Example usage of extension methods
// (Specific examples depend on available extension methods)
UseModernKdf = true for PBKDF2 support| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET Framework | net48 net48 is compatible. net481 net481 was computed. |
Showing the top 2 NuGet packages that depend on ZidUtilities.CommonCode:
| Package | Downloads |
|---|---|
|
ZidUtilities.CommonCode.Files
Library Classes to import data from files or export data to files. |
|
|
ZidUtilities.CommonCode.Log4Net
Provides classes to ease configuration of log4net appenders and also classes to read back these log files. I have not tested reading big log files, only a few thousand lines, I do not expect good performance with very large files. |
This package is not used by any popular GitHub repositories.
Fixed logic for FirstWord, GetWordNumber and WordCount.