CryptographicBuffer CryptographicBuffer CryptographicBuffer CryptographicBuffer Class

Contains static methods that implement data management functionality common to cryptographic operations.

Syntax

Declaration

public static class CryptographicBufferpublic static class CryptographicBufferPublic Static Class CryptographicBufferpublic static class CryptographicBuffer

Remarks

Examples

[!code-csharpShowCryptographicBufferOverview]

Methods summary

Compares two IBuffer objects.

Converts a buffer to an encoded string.

Converts a string to an encoded buffer.

Copies a buffer to an array of bytes.

Creates a buffer from an input byte array.

Decodes a string that has been base64 encoded.

Decodes a string that has been hexadecimal encoded.

Encodes a buffer to a base64 string.

Encodes a buffer to a hexadecimal string.

Creates a buffer that contains random data.

Creates a random number.

Methods

  • Compare(IBuffer, IBuffer)
    Compare(IBuffer, IBuffer)
    Compare(IBuffer, IBuffer)
    Compare(IBuffer, IBuffer)

    Compares two IBuffer objects.

    public static bool Compare(IBuffer object1, IBuffer object2)public static bool Compare(IBuffer object1, IBuffer object2)Public Static Function Compare(object1 As IBuffer, object2 As IBuffer) As boolpublic static bool Compare(IBuffer object1, IBuffer object2)

    Parameters

    Returns

    • bool
      bool
      bool
      bool

      True specifies that the buffers are equal. Two buffers are equal if each code point in one matches the corresponding code point in the other.

    Remarks

    Examples

    [!code-csharpShowBufferCompare]

  • ConvertBinaryToString(BinaryStringEncoding, IBuffer)
    ConvertBinaryToString(BinaryStringEncoding, IBuffer)
    ConvertBinaryToString(BinaryStringEncoding, IBuffer)
    ConvertBinaryToString(BinaryStringEncoding, IBuffer)

    Converts a buffer to an encoded string.

    public static string ConvertBinaryToString(BinaryStringEncoding encoding, IBuffer buffer)public static string ConvertBinaryToString(BinaryStringEncoding encoding, IBuffer buffer)Public Static Function ConvertBinaryToString(encoding As BinaryStringEncoding, buffer As IBuffer) As stringpublic static string ConvertBinaryToString(BinaryStringEncoding encoding, IBuffer buffer)

    Parameters

    Returns

    • string
      string
      string
      string

      A string that contains the encoded data.

    Remarks

    Examples

    [!code-csharpShowBinaryConversion]

  • ConvertStringToBinary(String, BinaryStringEncoding)
    ConvertStringToBinary(String, BinaryStringEncoding)
    ConvertStringToBinary(String, BinaryStringEncoding)
    ConvertStringToBinary(String, BinaryStringEncoding)

    Converts a string to an encoded buffer.

    public static IBuffer ConvertStringToBinary(String value, BinaryStringEncoding encoding)public static IBuffer ConvertStringToBinary(String value, BinaryStringEncoding encoding)Public Static Function ConvertStringToBinary(value As String, encoding As BinaryStringEncoding) As IBufferpublic static IBuffer ConvertStringToBinary(String value, BinaryStringEncoding encoding)

    Parameters

    Returns

    Remarks

    Examples

    [!code-csharpShowBinaryConversion]

  • CopyToByteArray(IBuffer, Byte[])
    CopyToByteArray(IBuffer, Byte[])
    CopyToByteArray(IBuffer, Byte[])
    CopyToByteArray(IBuffer, Byte[])

    Copies a buffer to an array of bytes.

    public static void CopyToByteArray(IBuffer buffer, Byte[] value)public static void CopyToByteArray(IBuffer buffer, Byte[] value)Public Static Function CopyToByteArray(buffer As IBuffer, value As Byte[]) As voidpublic static void CopyToByteArray(IBuffer buffer, Byte[] value)

    Parameters

    • buffer

      Input buffer.

    • value
      System.Byte[]
      System.Byte[]
      System.Byte[]
      System.Byte[]

      An array of bytes that contains the values copied from the input buffer. You must declare the array before calling this method and pass it by using the ref keyword. If the buffer for the input parameter is empty, then the value parameter will be returned as NULL.

    Remarks

    Examples

    [!code-csharpShowByteArrayCopy]

  • CreateFromByteArray(Byte[])
    CreateFromByteArray(Byte[])
    CreateFromByteArray(Byte[])
    CreateFromByteArray(Byte[])

    Creates a buffer from an input byte array.

    public static IBuffer CreateFromByteArray(Byte[] value)public static IBuffer CreateFromByteArray(Byte[] value)Public Static Function CreateFromByteArray(value As Byte[]) As IBufferpublic static IBuffer CreateFromByteArray(Byte[] value)

    Parameters

    • value
      System.Byte[]
      System.Byte[]
      System.Byte[]
      System.Byte[]

      An array of bytes used to create the buffer.

    Returns

    Remarks

    Examples

    [!code-csharpShowByteArrayCopy]

  • DecodeFromBase64String(String)
    DecodeFromBase64String(String)
    DecodeFromBase64String(String)
    DecodeFromBase64String(String)

    Decodes a string that has been base64 encoded.

    public static IBuffer DecodeFromBase64String(String value)public static IBuffer DecodeFromBase64String(String value)Public Static Function DecodeFromBase64String(value As String) As IBufferpublic static IBuffer DecodeFromBase64String(String value)

    Parameters

    • value
      System.String
      System.String
      System.String
      System.String

      Base64 encoded input string.

    Returns

    Remarks

    Base64 processes data as 24-bit groups, mapping each group to four encoded 8-bit characters. Base64 encoding is sometimes referred to as 3-to-4 encoding. Each 6 bits of the 24-bit group is used as an index into a mapping table (the base64 alphabet) to obtain a character for the encoded data.

    Examples

    [!code-csharpShowBase64Encoding]

  • DecodeFromHexString(String)
    DecodeFromHexString(String)
    DecodeFromHexString(String)
    DecodeFromHexString(String)

    Decodes a string that has been hexadecimal encoded.

    public static IBuffer DecodeFromHexString(String value)public static IBuffer DecodeFromHexString(String value)Public Static Function DecodeFromHexString(value As String) As IBufferpublic static IBuffer DecodeFromHexString(String value)

    Parameters

    • value
      System.String
      System.String
      System.String
      System.String

      Encoded input string.

    Returns

    Remarks

    Examples

    [!code-csharpShowHexEncoding]

  • EncodeToBase64String(IBuffer)
    EncodeToBase64String(IBuffer)
    EncodeToBase64String(IBuffer)
    EncodeToBase64String(IBuffer)

    Encodes a buffer to a base64 string.

    public static string EncodeToBase64String(IBuffer buffer)public static string EncodeToBase64String(IBuffer buffer)Public Static Function EncodeToBase64String(buffer As IBuffer) As stringpublic static string EncodeToBase64String(IBuffer buffer)

    Parameters

    Returns

    • string
      string
      string
      string

      Base64-encoded output string.

    Remarks

    Base64 processes data as 24-bit groups, mapping each group to four encoded 8-bit characters. Base64 encoding is sometimes referred to as 3-to-4 encoding. Each 6 bits of the 24-bit group is used as an index into a mapping table (the base64 alphabet) to obtain a character for the encoded data.

    Examples

    [!code-csharpShowBase64Encoding]

  • EncodeToHexString(IBuffer)
    EncodeToHexString(IBuffer)
    EncodeToHexString(IBuffer)
    EncodeToHexString(IBuffer)

    Encodes a buffer to a hexadecimal string.

    public static string EncodeToHexString(IBuffer buffer)public static string EncodeToHexString(IBuffer buffer)Public Static Function EncodeToHexString(buffer As IBuffer) As stringpublic static string EncodeToHexString(IBuffer buffer)

    Parameters

    Returns

    • string
      string
      string
      string

      Hexadecimal encoded output string.

    Remarks

    Examples

    [!code-csharpShowHexEncoding]

  • GenerateRandom(UInt32)
    GenerateRandom(UInt32)
    GenerateRandom(UInt32)
    GenerateRandom(UInt32)

    Creates a buffer that contains random data.

    public static IBuffer GenerateRandom(UInt32 length)public static IBuffer GenerateRandom(UInt32 length)Public Static Function GenerateRandom(length As UInt32) As IBufferpublic static IBuffer GenerateRandom(UInt32 length)

    Parameters

    • length
      System.UInt32
      System.UInt32
      System.UInt32
      System.UInt32

      Length, in bytes, of the buffer to create.

    Returns

    Remarks

    Examples

    [!code-csharpShowRandom]

  • GenerateRandomNumber()
    GenerateRandomNumber()
    GenerateRandomNumber()
    GenerateRandomNumber()

    Creates a random number.

    public static uint GenerateRandomNumber()public static uint GenerateRandomNumber()Public Static Function GenerateRandomNumber() As uintpublic static uint GenerateRandomNumber()

    Returns

    • uint
      uint
      uint
      uint

      Integer that contains the random data.

    Remarks

    Examples

    [!code-csharpShowRandom]

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.DualApiPartitionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.Security.Cryptography.dll