C# Class Akamai.Utils.ExtensionMethods

General utility functions needed to implement the NetStorageKit. Many of these functions are also available as standard parts of other libraries, but this package strives to operate without any external dependencies. Author: [email protected] (Colin Bendell)
ファイルを表示 Open project: surgeforward/AkamaiOPEN-edgegrid-C-Sharp Class Usage Examples

Public Methods

Method Description
ComputeHash ( this stream, ChecksumAlgorithm hashType = ChecksumAlgorithm.SHA256, long maxBodySize = null ) : byte[]

Computes the hash of a given InputStream. This is a wrapper over the HashAlgorithm crypto functions.

ComputeKeyedHash ( this data, string key, KeyedHashAlgorithm hashType = KeyedHashAlgorithm.HMACSHA256 ) : byte[]

Computes the HMAC hash of a given byte[]. This is a wrapper over the Mac crypto functions.

GetEpochSeconds ( this current ) : long

determine the number of seconds since unix epoch

ReadExactly ( this stream, long maxCount ) : byte[]

Reads a stream up to @maxCount number of bytes. Less bytes will be returned if the end of the file is reached.

ToBase64 ( this data ) : string

Base64-encode a byte array.

ToByteArray ( this data ) : byte[]

Retrieve the byte array for a string in UTF8 encoding

ToHex ( this data ) : string

Hex encoding wrapper for a byte array. The output will be 2 character padded string in lower case.

ToISO8601 ( this timestamp ) : string

format a date and time into ISO8601 style of "yyyyMMdd'T'HH:mm:ss+0000"

URLEncode ( this data ) : string

a utility method to uri encode a text string

Method Details

ComputeHash() public static method

Computes the hash of a given InputStream. This is a wrapper over the HashAlgorithm crypto functions.
public static ComputeHash ( this stream, ChecksumAlgorithm hashType = ChecksumAlgorithm.SHA256, long maxBodySize = null ) : byte[]
stream this the source stream. Use a MemoryStream if uncertain.
hashType ChecksumAlgorithm the Algorithm to use to compute the hash
maxBodySize long
return byte[]

ComputeKeyedHash() public static method

Computes the HMAC hash of a given byte[]. This is a wrapper over the Mac crypto functions.
public static ComputeKeyedHash ( this data, string key, KeyedHashAlgorithm hashType = KeyedHashAlgorithm.HMACSHA256 ) : byte[]
data this byte[] of content to hash
key string secret key to salt the hash. This is assumed to be UTF-8 encoded
hashType System.Security.Cryptography.KeyedHashAlgorithm determines which alogirthm to use. The recommendation is to use HMAC-SHA256
return byte[]

GetEpochSeconds() public static method

determine the number of seconds since unix epoch
public static GetEpochSeconds ( this current ) : long
current this the date and time to convert
return long

ReadExactly() public static method

Reads a stream up to @maxCount number of bytes. Less bytes will be returned if the end of the file is reached.
public static ReadExactly ( this stream, long maxCount ) : byte[]
stream this the stream to read
maxCount long the maximum number of bytes to read
return byte[]

ToBase64() public static method

Base64-encode a byte array.
public static ToBase64 ( this data ) : string
data this byte array to encode.
return string

ToByteArray() public static method

Retrieve the byte array for a string in UTF8 encoding
public static ToByteArray ( this data ) : byte[]
data this the data string
return byte[]

ToHex() public static method

Hex encoding wrapper for a byte array. The output will be 2 character padded string in lower case.
public static ToHex ( this data ) : string
data this a byte array to encode. The assumption is that the string to encode /// is small enough to be held in memory without streaming the encoding
return string

ToISO8601() public static method

format a date and time into ISO8601 style of "yyyyMMdd'T'HH:mm:ss+0000"
public static ToISO8601 ( this timestamp ) : string
timestamp this the date and time to convert
return string

URLEncode() public static method

a utility method to uri encode a text string
public static URLEncode ( this data ) : string
data this the string
return string