我不会用资产文件中的 .cer 文件加密我的字符串值。我找到了 c# 的代码。但是对于 Android,我该怎么做呢?
public string GetEncryptValue(string value)
{
X509Certificate2 x509_2 = w X509Certificate2(C:/publicCer.cer);//for android asset file
var encryptedValue = Encrypt(x509_2, value);
return encryptedValue;
}
public static string Encrypt(X509Certificate2 x509, string stringToEncrypt)
{
if (x509 == null || string.IsNullOrEmpty(stringToEncrypt))
throw new Exception("A x509 certificate and string for encryption must be provided");
RSACryptoServiceProvider rsa = (RSACryptoServiceProvider)x509.PublicKey.Key;
byte[] bytestoEncrypt = ASCIIEncoding.ASCII.GetBytes(stringToEncrypt);
byte[] encryptedBytes = rsa.Encrypt(bytestoEncrypt, false);
return Convert.ToBase64String(encryptedBytes);
}