CryptographicBuffer 类
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
包含实现加密操作通用的数据管理功能的静态方法。
public ref class CryptographicBuffer abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class CryptographicBuffer final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public static class CryptographicBuffer
Public Class CryptographicBuffer
- 继承
- 属性
Windows 要求
设备系列 |
Windows 10 (在 10.0.10240.0 中引入)
|
API contract |
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)
|
示例
public void CryptographicBufferOverview()
{
// 1. Generate random data.
UInt32 buffLength = 32;
IBuffer buffRnd = CryptographicBuffer.GenerateRandom(buffLength);
String strRndData = CryptographicBuffer.EncodeToHexString(buffRnd);
// 2. Generate a random number.
UInt32 Rnd = CryptographicBuffer.GenerateRandomNumber();
// 3. Decode a Base 64 string to a buffer and encode the buffer to a Base64 string.
String strBase64v1 = "uiwyeroiugfyqcajkds897945234==";
IBuffer buffFromBase64 = CryptographicBuffer.DecodeFromBase64String(strBase64v1);
String strBase64v2 = CryptographicBuffer.EncodeToBase64String(buffFromBase64);
// 4. Decode a hexadecimal string to a buffer and encode the buffer to a hexadecimal string.
String strHexv1 = "30310AFF";
IBuffer buffFromHex = CryptographicBuffer.DecodeFromHexString(strHexv1);
String strHexv2 = CryptographicBuffer.EncodeToHexString(buffFromHex);
// 5. Convert a strings to binary data and convert binary data to strings.
String strIn = "Input String";
IBuffer buffUTF16BE = CryptographicBuffer.ConvertStringToBinary(strIn, BinaryStringEncoding.Utf16BE);
String strUTF16BE = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf16BE, buffUTF16BE);
IBuffer buffUTF16LE = CryptographicBuffer.ConvertStringToBinary(strIn, BinaryStringEncoding.Utf16LE);
String strUTF16LE = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf16LE, buffUTF16LE);
IBuffer buffUTF8 = CryptographicBuffer.ConvertStringToBinary(strIn, BinaryStringEncoding.Utf8);
String strUTF8 = CryptographicBuffer.ConvertBinaryToString(BinaryStringEncoding.Utf8, buffUTF8);
// 6. Create a buffer from a byte array and create a byte array from a buffer,
byte[] arrByte = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
IBuffer buffFromByteArr = CryptographicBuffer.CreateFromByteArray(arrByte);
byte[] arrByteNew;
CryptographicBuffer.CopyToByteArray(buffFromByteArr, out arrByteNew);
// 7. Compare two buffers. The following Boolean value is true because the code points are equal.
String strHex = "30310aff";
String strBase64 = "MDEK/w==";
IBuffer buff1 = CryptographicBuffer.DecodeFromHexString(strHex);
IBuffer buff2 = CryptographicBuffer.DecodeFromBase64String(strBase64);
Boolean bVal = CryptographicBuffer.Compare(buff1, buff2);
}
方法
Compare(IBuffer, IBuffer) |
比较两个 IBuffer 对象。 |
ConvertBinaryToString(BinaryStringEncoding, IBuffer) |
将缓冲区转换为编码字符串。 |
ConvertStringToBinary(String, BinaryStringEncoding) |
将字符串转换为编码缓冲区。 |
CopyToByteArray(IBuffer, Byte[]) |
将缓冲区复制到字节数组。 |
CreateFromByteArray(Byte[]) |
从输入字节数组创建缓冲区。 |
DecodeFromBase64String(String) |
解码已 base64 编码的字符串。 |
DecodeFromHexString(String) |
解码已经过十六进制编码的字符串。 |
EncodeToBase64String(IBuffer) |
将缓冲区编码为 base64 字符串。 |
EncodeToHexString(IBuffer) |
将缓冲区编码为十六进制字符串。 |
GenerateRandom(UInt32) |
创建包含随机数据的缓冲区。 |
GenerateRandomNumber() |
创建一个随机数。 |