编码和解码数据
此示例代码演示如何在 通用 Windows 平台 (UWP) 应用中对 base64 和十六进制数据进行编码和解码。
public void EncodeDecodeBase64()
{
// Define a Base64 encoded string.
String strBase64 = "uiwyeroiugfyqcajkds897945234==";
// Decoded the string from Base64 to binary.
IBuffer buffer = CryptographicBuffer.DecodeFromBase64String(strBase64);
// Encode the buffer back into a Base64 string.
String strBase64New = CryptographicBuffer.EncodeToBase64String(buffer);
}
public void EncodeDecodeHex()
{
// Define a hexadecimal string.
String strHex = "30310AFF";
// Decode a hexadecimal string to binary.
IBuffer buffer = CryptographicBuffer.DecodeFromHexString(strHex);
// Encode the buffer back into a hexadecimal string.
String strHexNew = CryptographicBuffer.EncodeToHexString(buffer);
}