C#.NET史上最全字符串加密/解密/数字签名工具(CryptoHelper.cs)
C#.NET史上最全字符串加密/解密/数字签名工具(CryptoHelper.cs)
C# Code:
string text = "www.csframework.com/www.cscode.net C/S框架网测试";
txtResponse.Text = CryptoHelper.ToMD5(text);
MessageBox.Show("ToMD5:" txtResponse.Text);
txtResponse.Text = CryptoHelper.ToSHA256Hash(text);
MessageBox.Show("ToSHA256Hash:" txtResponse.Text);
txtResponse.Text = CryptoHelper.ToSHA512Hash(text);
MessageBox.Show("ToSHA512Hash:" txtResponse.Text);
string privateKey; string publicKey;
CryptoHelper.DSAGetKey(out privateKey, out publicKey);
txtResponse.Text = CryptoHelper.DSASign(text, privateKey);
MessageBox.Show("DSASign:" txtResponse.Text);
bool ss = CryptoHelper.DSAVerify(text, txtResponse.Text, publicKey);
txtResponse.Text = ss ? "验证成功" : "验证失败";
MessageBox.Show("DSAVerify:" txtResponse.Text);
CryptoHelper.RSAGetKey(out privateKey, out publicKey);
txtResponse.Text = CryptoHelper.RSAEncrypt(text, publicKey);
MessageBox.Show("RSAEncrypt:" txtResponse.Text);
txtResponse.Text = CryptoHelper.RSADecrypt(txtResponse.Text, privateKey);
MessageBox.Show("RSADecrypt:" txtResponse.Text);
txtResponse.Text = CryptoHelper.RSASign(text, privateKey);
MessageBox.Show("RSASign:" txtResponse.Text);
bool ok = CryptoHelper.RSAVerify(text, txtResponse.Text, publicKey);
txtResponse.Text = ok ? "验证成功" : "验证失败";
MessageBox.Show("RSAVerify:" txtResponse.Text);
txtResponse.Text = CryptoHelper.TripleDESEncrypt(text, "ABCDEFGHIJKLMNOP", "12345678");
MessageBox.Show(CryptoHelper.TripleDESDecrypt(txtResponse.Text, "ABCDEFGHIJKLMNOP", "12345678"));
txtResponse.Text = CryptoHelper.RijndaelEncrypt(text, "12345678", "12345678");
MessageBox.Show(CryptoHelper.RijndaelDecrypt(txtResponse.Text, "12345678", "12345678"));
txtResponse.Text = CryptoHelper.DESEncrypt(text, "12345678", "12345678");
MessageBox.Show(CryptoHelper.DESDecrypt(txtResponse.Text, "12345678", "12345678"));
//来源:C/S框架网(www.csframework.com) QQ:1980854898
string text = "www.csframework.com/www.cscode.net C/S框架网测试";
txtResponse.Text = CryptoHelper.ToMD5(text);
MessageBox.Show("ToMD5:" txtResponse.Text);
txtResponse.Text = CryptoHelper.ToSHA256Hash(text);
MessageBox.Show("ToSHA256Hash:" txtResponse.Text);
txtResponse.Text = CryptoHelper.ToSHA512Hash(text);
MessageBox.Show("ToSHA512Hash:" txtResponse.Text);
string privateKey; string publicKey;
CryptoHelper.DSAGetKey(out privateKey, out publicKey);
txtResponse.Text = CryptoHelper.DSASign(text, privateKey);
MessageBox.Show("DSASign:" txtResponse.Text);
bool ss = CryptoHelper.DSAVerify(text, txtResponse.Text, publicKey);
txtResponse.Text = ss ? "验证成功" : "验证失败";
MessageBox.Show("DSAVerify:" txtResponse.Text);
CryptoHelper.RSAGetKey(out privateKey, out publicKey);
txtResponse.Text = CryptoHelper.RSAEncrypt(text, publicKey);
MessageBox.Show("RSAEncrypt:" txtResponse.Text);
txtResponse.Text = CryptoHelper.RSADecrypt(txtResponse.Text, privateKey);
MessageBox.Show("RSADecrypt:" txtResponse.Text);
txtResponse.Text = CryptoHelper.RSASign(text, privateKey);
MessageBox.Show("RSASign:" txtResponse.Text);
bool ok = CryptoHelper.RSAVerify(text, txtResponse.Text, publicKey);
txtResponse.Text = ok ? "验证成功" : "验证失败";
MessageBox.Show("RSAVerify:" txtResponse.Text);
txtResponse.Text = CryptoHelper.TripleDESEncrypt(text, "ABCDEFGHIJKLMNOP", "12345678");
MessageBox.Show(CryptoHelper.TripleDESDecrypt(txtResponse.Text, "ABCDEFGHIJKLMNOP", "12345678"));
txtResponse.Text = CryptoHelper.RijndaelEncrypt(text, "12345678", "12345678");
MessageBox.Show(CryptoHelper.RijndaelDecrypt(txtResponse.Text, "12345678", "12345678"));
txtResponse.Text = CryptoHelper.DESEncrypt(text, "12345678", "12345678");
MessageBox.Show(CryptoHelper.DESDecrypt(txtResponse.Text, "12345678", "12345678"));
//来源:C/S框架网(www.csframework.com) QQ:1980854898
版权声明:本文为开发框架文库发布内容,转载请附上原文出处连接
NewDoc C/S框架网