| 
 | 
	
 
 
  [源码下载] 
 
 
 
 
重新想象 Windows 8 Store Apps (32) - 加密解密: 非对称算法, 数据转换的辅助类   
作者:webabcd 
 
介绍 
重新想象 Windows 8 Store Apps 之 加密解密 
 
 
- 非对称算法(RSA)
 
 - 签名和验证签名(RSA)
 
 - 通过 CryptographicBuffer 来实现 string hex base64 binary 间的相互转换
 
     
示例 
1、演示如何使用非对称算法(RSA) 
Crypto/Asymmetric.xaml.cs 
 
 
 
/* 
* 演示如何使用非对称算法(RSA) 
*/ 
using System; 
using Windows.Security.Cryptography; 
using Windows.Security.Cryptography.Core; 
using Windows.Storage.Streams; 
using Windows.UI.Xaml; 
using Windows.UI.Xaml.Controls; 
namespace XamlDemo.Crypto 
{ 
public sealed partial class Asymmetric : Page 
{ 
public Asymmetric() 
{ 
this.InitializeComponent(); 
} 
private void btnDemo_Click(object sender, RoutedEventArgs e) 
{ 
string plainText = "i am webabcd"; 
uint keySize = 2048; 
lblMsg.Text = "原文: " + plainText; 
lblMsg.Text += Environment.NewLine; 
lblMsg.Text += "keySize: " + keySize / 8; 
lblMsg.Text += Environment.NewLine; 
lblMsg.Text += Environment.NewLine; 
string[] algorithmNames = { "RSA_PKCS1", "RSA_OAEP_SHA1", "RSA_OAEP_SHA256", "RSA_OAEP_SHA384", "RSA_OAEP_SHA512" }; 
foreach (var algorithmName in algorithmNames) 
{ 
/* 
* 对于 RSA 非对称加密来说,其对原文的长度是有限制的,所以一般用 RSA 来加密对称算法的密钥 
*  
* RSA_PKCS1 要求原文长度 |   
 
 
 
 | 
  
 |