CryptographyUtility

Common cryptography methods.

Namespace:
Inetdev.Security.Cryptography
Type:
Class
Public:
Yes
Protected:
No
Sealed:
Yes
Abstract:
Yes
Inherits from:
System.Object

Methods

CombineBytes

Combines two byte arrays into one.

Signature:
public Byte[] CombineBytes(buffer1, buffer2)
Returns

The combined byte array.

Parameters
Name Type Summary
buffer1 Byte[] The prefixed bytes.
buffer2 Byte[] The suffixed bytes.
Exceptions
Type Summary
ArgumentNullException Thrown when any of the input parameters are null.

CompareBytes

Determine if two byte arrays are equal.

Signature:
public Boolean CompareBytes(byte1, byte2)
Returns

true if the two byte array are equal; otherwise false.

Parameters
Name Type Summary
byte1 Byte[] The first byte array to compare.
byte2 Byte[] The byte array to compare to the first.

CreateUniqueId

Creates a unique ID from random bytes and converter it to an hexadecimal string. The resulting string is twice the size of the asked id size.

Signature:
public String CreateUniqueId(length)
Returns

A randomly generated unique id.

Parameters
Name Type Summary
length Int32 Length of the key to generate.

GetRandomAlphanumericBytes

Fills a byte array with a random set of aplhanumeric bytes.

Signature:
public Void GetRandomAlphanumericBytes(bytes)
Parameters
Name Type Summary
bytes Byte[] The byte array to fill.

GetRandomAlphanumericBytes

Creates a random set of alphanumeric bytes.

Signature:
public Byte[] GetRandomAlphanumericBytes(size)
Returns

The computes bytes.

Parameters
Name Type Summary
size Int32 The size of the byte array to generate.

GetRandomBytes

Fills a byte array with a cryptographically strong random set of bytes.

Signature:
public Void GetRandomBytes(bytes)
Parameters
Name Type Summary
bytes Byte[] The byte array to fill.

GetRandomBytes

Creates a cryptographically strong random set of bytes.

Signature:
public Byte[] GetRandomBytes(size)
Returns

The computed bytes.

Parameters
Name Type Summary
size Int32 The size of the byte array to generate.

Transform

Transform an array of bytes according to the given cryptographic transform.

Signature:
public Byte[] Transform(transform, buffer)
Returns

Transformed array of bytes. It is the responsability of the caller to clear this byte array if necessary.

Parameters
Name Type Summary
transform ICryptoTransform ICryptoTransform used to transform the given buffer.
buffer Byte[] Buffer to transform. It is the responsability of the caller to clear this array when finished.
Exceptions
Type Summary
ArgumentNullOrEmptyException

Thrown when the buffer is null.

-or- buffer.Length is zero.

CryptographyException Thrown when an error occurs while transforming the data.

TransformStream

Transforms the source stream into the destination stream using the given cryptographic transform.

Signature:
public Void TransformStream(transform, source, destination)
Parameters
Name Type Summary
transform ICryptoTransform ICryptoTransform used to transform the stream.
source Stream The Stream to transform.
destination Stream The destination stream to put the results in.
Exceptions
Type Summary
ArgumentNullException

Thrown when transform is null.

-or- source is null.

-or- destination is null.

CryptographyException Thrown when an error occurs while transforming the data.

ZeroOutBytes

Fills bytes zeros.

Signature:
public Void ZeroOutBytes(bytes)
Parameters
Name Type Summary
bytes Byte[] The byte array to fill.