using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
namespace CSSTUDY
{
class Code
{
public static CspParameters param;
public static string Md5Encrypt(string sourceStr)
{
MD5 md5 = new MD5CryptoServiceProvider();
byte[] palindata = Encoding.Default.GetBytes(sourceStr);
byte[] encryptdata = md5.ComputeHash(palindata);
string returnData = Convert.ToBase64String(encryptdata);
return returnData;
}
public static string RsaEncrypt(string sourceStr)
{
param = new CspParameters();
param.KeyContainerName = "Navis";
using (RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(param))
{
byte[] plaindata = Encoding.Default.GetBytes(sourceStr);
byte[] encryptdata = rsa.Encrypt(plaindata, false);
return Convert.ToBase64String(encryptdata);
}
}
public static string RsaDesEncrypt(string codingStr)
{
param = new CspParameters();
param.KeyContainerName = "Navis";
using(RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(param))
{
byte[] encryptdata = Convert.FromBase64String(codingStr);
byte[] decryptdata = rsa.Decrypt(encryptdata, false);
return Encoding.Default.GetString(decryptdata);
}
}
}
}
using System
using System.Collections.Generic
using System.Linq
using System.Text
namespace CSSTUDY
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Code.Md5Encrypt("navis"))
Console.ReadKey()
string pwd = Code.RsaEncrypt("Navis_123")
Console.WriteLine(pwd)
Console.ReadKey()
Console.WriteLine(Code.RsaDesEncrypt(pwd))
Console.ReadKey()
}
}
}