NamespaceSystemLibrary.Common.Net.Extensions SystemLibrary.Common.Net.dll
ByteArrayExtensions
public static class ByteArrayExtensions
Inheritance
System.Object
ByteArrayExtensions
Examples
Arguments
X
Methods
Return a base64 string of the bytes
If input is null or empty it returns null or empty string
public static string ToBase64(this byte[] bytes)
X
var bytes = "hello world".GetBytes();
var base64string = bytes.ToBase64();
//Tip: If you dont need base64 format, .Obfuscating() method is faster if data is less than ~400KB
X
Methods arguments
Type | Name | Description |
---|---|---|
System.Byte[] | bytes |
X
Type | Description |
---|---|
System.String |
Returns a hash string of the bytes
If input is null or empty it returns null or empty string
Tip: If data is larger than ~200 bytes then .ToSha1Hash() is faster
public static string ToMD5Hash(this byte[] bytes)
X
var bytes = "hello world".GetBytes();
var md5string = bytes.ToMD5Hash();
X
Methods arguments
Type | Name | Description |
---|---|---|
System.Byte[] | bytes |
X
Type | Description |
---|---|
System.String |
Returns a sha1 hash string of the bytes
If input is null or empty it returns null or empty string
Tip: If data is less than ~200 bytes then .ToMD5Hash() is faster
public static string ToSha1Hash(this byte[] bytes)
X
var bytes = "hello world".GetBytes();
var sha1string = bytes.ToSha1Hash();
X
Methods arguments
Type | Name | Description |
---|---|---|
System.Byte[] | bytes |
X
Type | Description |
---|---|
System.String |
Returns a sha 256 hash string of the bytes
If input is null or empty it returns null or empty string
public static string ToSha256Hash(this byte[] bytes)
X
var bytes = "hello world".GetBytes();
var sha256string = bytes.ToSha256Hash();
X
Methods arguments
Type | Name | Description |
---|---|---|
System.Byte[] | bytes |
X
Type | Description |
---|---|
System.String |
Return a text representation of the bytes
If input is null or empty, it returns null or empty string
public static string ToText(this byte[] bytes, Encoding encoding = null)
X
var bytes = "hello world".GetBytes();
var text = bytes.ToText(); //text == hello world
X
Methods arguments
Type | Name | Description |
---|---|---|
System.Byte[] | bytes | |
System.Text.Encoding | encoding |
X
Type | Description |
---|---|
System.String |
}