我需要生成一个 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);