|
|
hstarorg / hstardemoproject Goto Github PK
View Code? Open in Web Editor NEWsome demo codes.
License: MIT License
some demo codes.
License: MIT License
代码如下:
static void Main(string[] args)
{
var rsaHelper = new RsaHelper();
var test1 =
"i0s9lv0QuefmmXWkWxqIwJMcK1/uOjTTIpc0K2YWAwFGuMSbQ651Zfl4i7MY/Qi/vG8+J7SRyb3UWiS5CNP3M3MI2tC6l2CVAGv0godSMaeWbMqj9g17KwJr9r3EYtPvc8lRi8ec3qS8plkoPUCoz3PtsK LZ9hBlAXKD3f8qGDI=";
var key = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCxtkuwBI6novN6IKoP3AUe7vQnT +3NqYy0SJqGTf4u5sWuKj6jwpvBSf17DoBGAXPVfzQjtl3xNymn/87c7qzDzollBH1dXAdg5olwp0tAUVEWDKuCgaFGjsqnrTYxTvOqTf1J08mIQf3Tngkw1WuNBdADUiBsTlgpO9k+ffIL4wIDAQAB";
var source = rsaHelper.DecryptByPublibKey(test1, key);
Console.WriteLine("通过公钥解密后的原文是:{0}", source);
Console.ReadKey();
}
///
/// 公钥解密(key公钥解密)- 必须对应私钥加密
/// </summary>
/// <param name="source">加密后的数据(密文)</param>
/// <param name="publicKey">公钥</param>
/// <returns></returns>
public string DecryptByPublibKey(string source, string publicKey)
{
var publicInfoByte = Convert.FromBase64String(publicKey);
Asn1Object pubKeyObj = Asn1Object.FromByteArray(publicInfoByte);//这里也可以从流中读取,从本地导入
AsymmetricKeyParameter pubKey = PublicKeyFactory.CreateKey(SubjectPublicKeyInfo.GetInstance(pubKeyObj));
//开始解密
IAsymmetricBlockCipher cipher = new RsaEngine();
cipher.Init(false, pubKey);
//解密已加密的数据
byte[] encryptedData = Convert.FromBase64String(source);
encryptedData = cipher.ProcessBlock(encryptedData, 0, encryptedData.Length);
return Encoding.UTF8.GetString(encryptedData, 0, encryptedData.Length);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.