我尝试使用该代码但是当Decrypt行发生时,我得到的值不在Decrypt mathod的预期范围异常范围内
这是单身类,所以他创建了一次密钥
{
public class CryptographyProvider
{
private CryptographicKey key;
public CryptographyProvider()
{
String AsymmetricAlgName = Windows.Security.Cryptography.Core.AsymmetricAlgorithmNames.RsaPkcs1;
AsymmetricKeyAlgorithmProvider asym = AsymmetricKeyAlgorithmProvider.OpenAlgorithm(AsymmetricAlgName);
key = asym.CreateKeyPair(512);
}
public string Encrypt(string source)
{
IBuffer buf = CryptographicBuffer.ConvertStringToBinary(source, BinaryStringEncoding.Utf16BE);
IBuffer enc = CryptographicEngine.Encrypt(key, buf, null);
byte[] encryptedbyteArr;
CryptographicBuffer.CopyToByteArray(enc, out encryptedbyteArr);
var ret = Convert.ToBase64String(encryptedbyteArr);
return ret;
}
public string Decrypt(string source)
{
IBuffer buf = CryptographicBuffer.ConvertStringToBinary(source, BinaryStringEncoding.Utf16BE);
IBuffer enc = CryptographicEngine.Decrypt(key, buf, null);
byte[] encryptedbyteArr;
CryptographicBuffer.CopyToByteArray(enc, out encryptedbyteArr);
var ret = Convert.ToBase64String(encryptedbyteArr);
return ret;
}
}
}
我的代码有什么问题?