本文整理汇总了C#中System.Security.Cryptography.RSACryptoServiceProvider.LoadPublicKeyPEM方法的典型用法代码示例。如果您正苦于以下问题:C# RSACryptoServiceProvider.LoadPublicKeyPEM方法的具体用法?C# RSACryptoServiceProvider.LoadPublicKeyPEM怎么用?C# RSACryptoServiceProvider.LoadPublicKeyPEM使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.Cryptography.RSACryptoServiceProvider
的用法示例。
在下文中一共展示了RSACryptoServiceProvider.LoadPublicKeyPEM方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VerifySignedHash
public static string VerifySignedHash(string str_DataToVerify, string str_SignedData, string str_publicKeyFilePath)
{
byte[] SignedData = Convert.FromBase64String(str_SignedData);
UTF8Encoding ByteConverter = new UTF8Encoding();
byte[] DataToVerify = ByteConverter.GetBytes(str_DataToVerify);
try
{
string sPublicKeyPEM = File.ReadAllText(str_publicKeyFilePath);
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
rsa.PersistKeyInCsp = false;
rsa.LoadPublicKeyPEM(sPublicKeyPEM);
if (rsa.VerifyData(DataToVerify, "SHA256", SignedData))
{
return "verify success";
}
else
{
return "verify fail";
}
}
catch (CryptographicException e)
{
Console.WriteLine(e.Message);
return "verify error";
}
}
示例2: Main
static int Main(string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
oldpass = File.ReadAllText(@"oldPass.txt");
newpass = NewPass(oldpass);
WebRequest request;
{
string encrypted;
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(1024))
{
rsa.PersistKeyInCsp = false;
rsa.LoadPublicKeyPEM(File.ReadAllText(@"pubkey.pem", Encoding.UTF8));
encrypted = Convert.ToBase64String(rsa.Encrypt(Encoding.UTF8.GetBytes(newpass), false));
}
request = WebRequest.Create(
// Zebra Crossing site was unavailable on October, 23rd
//@"http://zxing.org/w/chart?cht=qr&chs=350x350&chld=L&choe=UTF-8&chl=" +
@"http://api.qrserver.com/v1/create-qr-code/?data=" +
Uri.EscapeDataString(encrypted));
}
using (var qrcode = new MemoryStream())
{
using (var response = request.GetResponse())
response.GetResponseStream().CopyTo(qrcode);
var uploadTo = File.ReadAllText(@"uploadTo.url", Encoding.UTF8);
var match = new Regex(@"^\w://(?<Credentials>(?<User>[^:@/]+):(?<Pass>[^@/]+)@)").Match(uploadTo);
if (match.Success)
{
uploadTo = uploadTo.Remove(match.Groups[@"Credentials"].Index, match.Groups[@"Credentials"].Length);
request = WebRequest.Create(uploadTo);
request.Credentials = new NetworkCredential(match.Groups[@"User"].Value, match.Groups[@"Pass"].Value);
}
else
request = WebRequest.Create(uploadTo);
try
{
request.Timeout = 20000;
}
catch { }
try
{
((FtpWebRequest)request).Method = WebRequestMethods.Ftp.UploadFile;
((FtpWebRequest)request).UsePassive = true;
}
catch
{
try
{
((HttpWebRequest)request).Method = WebRequestMethods.Http.Put;
}
catch
{
try
{
((FileWebRequest)request).Method = WebRequestMethods.File.UploadFile;
}
catch
{
throw new Exception(@"Unknown protocol in your URL, please check file: uploadTo.url");
}
}
}
try
{
request.ContentLength = qrcode.Length;
}
catch { }
try
{
request.ContentType = @"image/png";
}
catch { }
using (var stream = request.GetRequestStream())
qrcode.WriteTo(stream);
request.GetResponse();
}
return 0;
}
示例3: VerifyRSASignature
public static bool VerifyRSASignature(string data, string expectedSignature)
{
string sPublicKeyPEM = File.ReadAllText(System.Windows.Forms.Application.StartupPath + "\\T8Pub.pem");
var dataToSign = Encoding.UTF8.GetBytes(data);
var signature = Convert.FromBase64String(expectedSignature);
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider())
{
rsa.PersistKeyInCsp = false;
rsa.LoadPublicKeyPEM(sPublicKeyPEM);
using (SHA1CryptoServiceProvider sha1 = new SHA1CryptoServiceProvider())
return rsa.VerifyData(dataToSign, sha1, signature);
}
}