110,570
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
using System.Security.Cryptography;
namespace AspCSharp
{
class RSA:Help
{
public string Help()
{
return "";
}
private RSACryptoServiceProvider rsa;
public RSA()
{
CspParameters RSAParams = new CspParameters();
RSAParams.Flags = CspProviderFlags.UseMachineKeyStore;
rsa = new RSACryptoServiceProvider(1024, RSAParams);
}
public void setKey(string key)
{
rsa.FromXmlString(key);
}
public string getKey()
{
return rsa.ToXmlString(true);
}
public string enByPublic(string str) {
return Convert.ToBase64String(rsa.Encrypt(Encoding.UTF8.GetBytes(str), false));
}
public string enByPrivate() {
throw new NotSupportedException();
}
public string deByPublic()
{
throw new NotSupportedException();
}
public string deByPrivate(string str)
{
return Encoding.UTF8.GetString(rsa.Decrypt(Convert.FromBase64String(str), false));
}
}
}