项目介绍
Z.ExtensionMethods 是一个为 .NET Framework 和 .NET Core 提供超过 1000 个扩展方法的库。这些扩展方法极大地增强了 .NET 框架的功能,使得开发者可以更方便、快捷地进行编程。
Z.ExtensionMethods 采用 MIT 许可证,这意味着它可以自由地用于商业项目,只需包含许可证文件并遵守其条款即可。

主要特点
-
-
超过 1000 个扩展方法:覆盖了字符串、集合、数学、日期时间等多个方面,旨在简化常见编程任务。 -
支持 .NET Framework 和 .NET Core:确保跨平台兼容性和广泛的应用场景。
-
-
易于集成:通过 NuGet 包管理器轻松安装,无需额外配置。
拓展分类

Online Examples
-
https://csharp-extension.com/

sha256 sample
namespace Host.Core.Encryption
{
using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
public class Program
{
public static void Main(string[] args)
{
String enc = "kx1XhI+HozFBcssEZyNE8Q==";
String key = "hangfire_praiadosal10host";
Console.WriteLine(enc);
Console.WriteLine(RijndaelSimple.Decrypt(enc, key));
}
public class RijndaelSimple
{
private static string _saltValue = "my salt value 123";
private static string _hashAlgorithm = "SHA1";
private static int _passwordIterations = 2;
private static string _initVector = "@1B2c4D4e596g7H8";
private static int _keySize = 0x100;
public static string Decrypt(string cipherText, string passPhrase)
{
byte[] bytes = Encoding.ASCII.GetBytes(_saltValue);
byte[] buffer = Convert.FromBase64String(cipherText);
RijndaelManaged managed = new RijndaelManaged {
Mode = CipherMode.CBC
};
MemoryStream stream = new MemoryStream(buffer);
CryptoStream stream2 = new CryptoStream(stream, managed.CreateDecryptor(new PasswordDeriveBytes(passPhrase, bytes, _hashAlgorithm, _passwordIterations).GetBytes(_keySize / 8), Encoding.ASCII.GetBytes(_initVector)), CryptoStreamMode.Read);
byte[] buffer5 = new byte[buffer.Length];
stream.Close();
stream2.Close();
return Encoding.UTF8.GetString(buffer5, 0, stream2.Read(buffer5, 0, buffer5.Length));
}
public static string Encrypt(string plainText, string passPhrase)
{
byte[] bytes = Encoding.ASCII.GetBytes(_saltValue);
byte[] buffer = Encoding.UTF8.GetBytes(plainText);
RijndaelManaged managed = new RijndaelManaged {
Mode = CipherMode.CBC
};
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, managed.CreateEncryptor(new PasswordDeriveBytes(passPhrase, bytes, _hashAlgorithm, _passwordIterations).GetBytes(_keySize / 8), Encoding.ASCII.GetBytes(_initVector)), CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
byte[] inArray = stream.ToArray();
stream.Close();
stream2.Close();
return Convert.ToBase64String(inArray);
}
}
}
}
ToMD5Hash
// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002047/stream-tomd5hash
// @nuget: Z.ExtensionMethods
using System;
using System.IO;
public class Program
{
public static string FileName = "test.txt";
public static void Main()
{
SaveFile();
using (StreamReader sr = File.OpenText(FileName))
{
// C# Extension Method: Stream - ToMD5Hash
string hash = sr.BaseStream.ToMD5Hash();
Console.WriteLine(hash);
}
}
private static void SaveFile()
{
var html =
@"<!DOCTYPE html>
<html>
<body>
<h1>This is <b>bold</b> heading</h1>
<p>This is <u>underlined</u> paragraph</p>
<h2>This is <i>italic</i> heading</h2>
</body>
</html> ";
html.SaveAs(FileName);
}
}
版权声明:
1、本网站名称:帝企吧
2、本站永久网址:https://www.diqiba.com
3、本网站的文章部分内容可能来源于网络及作者投稿,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报。
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
7、本站所有资源来源于互联网,仅用于学习及参考使用,切勿用于商业用途,如产生法律纠纷本站概不负责! 8、资源除标明原创外均来自网络转载,版权归原作者所有,若侵犯到您权益请联系我们删除,我们将及时处理! 9、若您需使用非免费的软件或服务,请购买正版授权并合法使用!
1、本网站名称:帝企吧
2、本站永久网址:https://www.diqiba.com
3、本网站的文章部分内容可能来源于网络及作者投稿,仅供大家学习与参考,如有侵权,请联系站长进行删除处理。
4、本站一切资源不代表本站立场,并不代表本站赞同其观点和对其真实性负责。
5、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报。
6、本站资源大多存储在云盘,如发现链接失效,请联系我们我们会第一时间更新。
7、本站所有资源来源于互联网,仅用于学习及参考使用,切勿用于商业用途,如产生法律纠纷本站概不负责! 8、资源除标明原创外均来自网络转载,版权归原作者所有,若侵犯到您权益请联系我们删除,我们将及时处理! 9、若您需使用非免费的软件或服务,请购买正版授权并合法使用!

评论(0)