MAUI 或 .net 标准中的 Windows.Security.Cryptography.CryptographicBuffer.DecodeFromBase64String 替换
我正在尝试将 UWP 应用程序转换为 MAUI。 尝试转换以下函数。 MAUI(.net6 或 .net 标准)中的 Windows.Security.Cryptography.CryptographicBuffer.DecodeFromBase64String(publicKey)
等效项是什么。
public static string EncryptUsingAsymmetricPublicKey(string data)
{
string publicKey = "MIGJAoGBAJTxJ6xRdgcPXi4/0KK73FBDuI5VGZnIi7IblIY/wxcuGagBEvzlYEqJaWVO3l5aTbnnB63DU5eBlR0nnzUC+UM6b/PBmFGUyDaXYK6msThvvxAqj32UjLvYyq5S+Z57Y/cv/0vokOfTdEyTMw+WTbJh7c2npj9IAFnc32Z5PknVAgMBAAE=";
//converting the public key into an IBuffer
IBuffer keyBuffer = CryptographicBuffer.DecodeFromBase64String(publicKey);
//load the public key and the algorithm provider
var asym = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaPkcs1);
var cryptoKey = asym.ImportPublicKey(keyBuffer, CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey);
//converting the string into an IBuffer
IBuffer buffer = CryptographicBuffer.ConvertStringToBinary(data, BinaryStringEncoding.Utf8);
//perform the encryption
var encryptedBytesBuffer = CryptographicEngine.Encrypt(cryptoKey, buffer, null);
//convert to base 64
return CryptographicBuffer.EncodeToBase64String(encryptedBytesBuffer);
}
I am trying to convert UWP application to MAUI.
Trying to convert following function. What is the equivalent of Windows.Security.Cryptography.CryptographicBuffer.DecodeFromBase64String(publicKey)
in MAUI (.net6 or .net standard).
public static string EncryptUsingAsymmetricPublicKey(string data)
{
string publicKey = "MIGJAoGBAJTxJ6xRdgcPXi4/0KK73FBDuI5VGZnIi7IblIY/wxcuGagBEvzlYEqJaWVO3l5aTbnnB63DU5eBlR0nnzUC+UM6b/PBmFGUyDaXYK6msThvvxAqj32UjLvYyq5S+Z57Y/cv/0vokOfTdEyTMw+WTbJh7c2npj9IAFnc32Z5PknVAgMBAAE=";
//converting the public key into an IBuffer
IBuffer keyBuffer = CryptographicBuffer.DecodeFromBase64String(publicKey);
//load the public key and the algorithm provider
var asym = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgorithmNames.RsaPkcs1);
var cryptoKey = asym.ImportPublicKey(keyBuffer, CryptographicPublicKeyBlobType.Pkcs1RsaPublicKey);
//converting the string into an IBuffer
IBuffer buffer = CryptographicBuffer.ConvertStringToBinary(data, BinaryStringEncoding.Utf8);
//perform the encryption
var encryptedBytesBuffer = CryptographicEngine.Encrypt(cryptoKey, buffer, null);
//convert to base 64
return CryptographicBuffer.EncodeToBase64String(encryptedBytesBuffer);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
找到解决方案
Found solution