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