生成AES密钥并将其编码为Base 64 String

时间:2012-09-17 12:42:25

标签: c# windows-8 windows-runtime

我需要生成一个AES密钥并将其发送到服务器。

创建密钥似乎不是问题:

   var aesProvider = SymmetricKeyAlgorithmProvider.OpenAlgorithm(SymmetricAlgorithmNames.AesEcbPkcs7);

   var aesKey = aesProvider.CreateSymmetricKey(CryptographicBuffer.GenerateRandom(16));

但是,将AES密钥导出为base64编码的字符串似乎是不可能的;

我尝试使用关键对象上的Export / ExportPublic方法导出它,但它们都抛出NotImplemented异常:

 aesKey.ExportPublicKey(); not implemented
 aesKey.ExportPublicKey(CryptographicPublicKeyBlobType.BCryptPublicKey);
 aesKey.ExportPublicKey(CryptographicPublicKeyBlobType.Capi1PublicKey);
 aesKey.Export();
 aesKey.Export(CryptographicPrivateKeyBlobType.BCryptPrivateKey);
 aesKey.Export(CryptographicPrivateKeyBlobType.Pkcs1RsaPrivateKey);
 aesKey.Export(CryptographicPrivateKeyBlobType.Pkcs8RawPrivateKeyInfo);
 aesKey.Export(CryptographicPrivateKeyBlobType.Capi1PrivateKey);

0 个答案:

没有答案