44 lines
1.5 KiB
C#
44 lines
1.5 KiB
C#
using System;
|
||
using System.Security.Cryptography;
|
||
using System.Text;
|
||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||
|
||
namespace Cmdjy.Bll.Tests
|
||
{
|
||
[TestClass()]
|
||
public class DesHelperTests
|
||
{
|
||
[TestMethod()]
|
||
public void EncryptyTest() {
|
||
//byte[] IV = { 0x01,0x02,0x03,0x14,0x05,0x06,0x17,0x08 };
|
||
string key = "wscdy19;";
|
||
var des = DesHelper.GetHelper();
|
||
Console.WriteLine($"Key:{key}");
|
||
string mingwen = getMingWen();
|
||
Console.WriteLine($"明文:{mingwen}");
|
||
var miwen = des.Encrypty(key,mingwen);
|
||
Console.WriteLine($"密文:{miwen}");
|
||
var miwen2 = des.Encrypty(key,mingwen);
|
||
Console.WriteLine($"密文2:{miwen2}");
|
||
Assert.AreEqual(miwen,miwen2,"多次加密密文应该相同");
|
||
var mingwen2 = des.DesCrypty(key,miwen);
|
||
Assert.AreEqual(mingwen,mingwen2,"明文和密文相同");
|
||
}
|
||
|
||
public string getMingWen() {
|
||
string str = "abcdefghijklmnopqrstuvwxyz1234567890,./*-+{}[],.;\"";
|
||
var result = new StringBuilder();
|
||
int len = 100;
|
||
var rean = new Random();
|
||
for(int i = 0;i < len;i++) {
|
||
var p = rean.Next(str.Length);
|
||
result.Append(str.ToCharArray()[p]);
|
||
}
|
||
return result.ToString();
|
||
}
|
||
|
||
public string Realstr() {
|
||
return @"";
|
||
}
|
||
}
|
||
} |