CryptographicBuffer的使用技巧
来源:互联网 发布:centos无法用ssh指令 编辑:程序博客网 时间:2024/05/20 12:48
1.创建随机数
public string GenerateRandomData(){ // Define the length, in bytes, of the buffer. uint length = 32; // Generate random data and copy it to a buffer. IBuffer buffer = CryptographicBuffer.GenerateRandom(length); // Encode the buffer to a hexadecimal string (for display). string randomHex = CryptographicBuffer.EncodeToHexString(buffer); return public void CompareBuffers(){ // Create a hexadecimal string. String strHex = "30310aff"; // Create a Base64 string that is equivalent to strHex. String strBase64v1 = "MDEK/w=="; // Create a Base64 string that is not equivalent to strHex. String strBase64v2 = "KEDM/w=="; // Decode strHex to a buffer. IBuffer buff1 = CryptographicBuffer.DecodeFromHexString(strHex); // Decode strBase64v1 to a buffer. IBuffer buff2 = CryptographicBuffer.DecodeFromBase64String(strBase64v1); // Decode strBase64v2 to a buffer. IBuffer buff3 = CryptographicBuffer.DecodeFromBase64String(strBase64v2); // Compare the hexadecimal-decoded buff1 to the Base64-decoded buff2. // The code points in the two buffers are equal, and the Boolean value // is true. Boolean bVal_1 = CryptographicBuffer.Compare(buff1, buff2); // Compare the hexadecimal-decoded buff1 to the Base64-decoded buff3. // The code points in the two buffers are not equal, and the Boolean value // is false. Boolean bVal_2 = CryptographicBuffer.Compare(buff1, buff3);};}public uint GenerateRandomNumber(){ // Generate a random number. uint random = CryptographicBuffer.GenerateRandomNumber(); return random;}
2.比较缓存
public void CompareBuffers(){ // Create a hexadecimal string. String strHex = "30310aff"; // Create a Base64 string that is equivalent to strHex. String strBase64v1 = "MDEK/w=="; // Create a Base64 string that is not equivalent to strHex. String strBase64v2 = "KEDM/w=="; // Decode strHex to a buffer. IBuffer buff1 = CryptographicBuffer.DecodeFromHexString(strHex); // Decode strBase64v1 to a buffer. IBuffer buff2 = CryptographicBuffer.DecodeFromBase64String(strBase64v1); // Decode strBase64v2 to a buffer. IBuffer buff3 = CryptographicBuffer.DecodeFromBase64String(strBase64v2); // Compare the hexadecimal-decoded buff1 to the Base64-decoded buff2. // The code points in the two buffers are equal, and the Boolean value // is true. Boolean bVal_1 = CryptographicBuffer.Compare(buff1, buff2); // Compare the hexadecimal-decoded buff1 to the Base64-decoded buff3. // The code points in the two buffers are not equal, and the Boolean value // is false. Boolean bVal_2 = CryptographicBuffer.Compare(buff1, buff3);}
3.strings 和 binary转换
public void ConvertData(){ // Create a string to convert. String strIn = "Input String"; // Convert the string to UTF16BE binary data. IBuffer buffUTF16BE = CryptographicBuffer.ConvertStringToBinary(strIn, BinaryStringEncoding.Utf16BE); // Convert the string to UTF16LE binary data. IBuffer buffUTF16LE = CryptographicBuffer.ConvertStringToBinary(strIn, BinaryStringEncoding.Utf16LE); // Convert the string to UTF8 binary data. IBuffer buffUTF8 = CryptographicBuffer.ConvertStringToBinary(strIn, BinaryStringEncoding.Utf8);}
4.byte数组的复制
public void ByteArrayCopy(){ // Initialize a byte array. byte[] bytes = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; // Create a buffer from the byte array. IBuffer buffer = CryptographicBuffer.CreateFromByteArray(bytes); // Encode the buffer into a hexadecimal string (for display); string hex = CryptographicBuffer.EncodeToHexString(buffer); // Copy the buffer back into a new byte array. byte[] newByteArray; CryptographicBuffer.CopyToByteArray(buffer, out newByteArray);}
5.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);}
阅读全文
0 0
- CryptographicBuffer的使用技巧
- powerdesign 的使用技巧
- BCP的使用技巧
- native2ascii的使用技巧
- IE的使用技巧
- QQ的使用技巧
- Datawindow的使用技巧
- powerdesign 的使用技巧
- GVim的使用技巧
- ListView的使用技巧
- css的使用技巧
- NumberFormat的使用技巧
- Eclipse的使用技巧
- GridView的使用技巧.
- SlickEdit的使用技巧
- BCP的使用技巧
- powerdesign的使用技巧
- eclipse使用的技巧
- 当前的安全设置不允许从该位置下载文件。 的解决办法
- android studio 翻译插件,可以将英文翻译为中文
- 【oracle语法】-for update 与 rowid
- 进程间的八种通信方式
- 数据结构实验之图论十一:AOE网上的关键路径
- CryptographicBuffer的使用技巧
- Bootstrap模态框使用WebUploader点击失效问题解决
- Unity Shader中的概念及原理综述
- 浅谈模板引擎之artTemplate
- 文本情感分类—深度学习模型基本概念
- Merge Intervals
- PHPExcel 大数据的导出
- vue.js 学习笔记
- bootstrap上传插件fileinput自动上传&成功回调 转载 2016年10月11日 11:24:09 7141 bootstrap上传插件fileinput功能非常强大,本文给出一例自动上传