2019-03-14 14:12:09 +08:00
|
|
|
|
using System;
|
2019-03-07 16:10:37 +08:00
|
|
|
|
using System.Security.Cryptography;
|
2019-03-14 14:12:09 +08:00
|
|
|
|
using System.Text;
|
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2019-03-07 16:10:37 +08:00
|
|
|
|
|
|
|
|
|
namespace Cmdjy.Bll.Tests
|
|
|
|
|
{
|
|
|
|
|
[TestClass()]
|
|
|
|
|
public class DesHelperTests
|
|
|
|
|
{
|
|
|
|
|
[TestMethod()]
|
|
|
|
|
public void EncryptyTest() {
|
2019-03-14 14:12:09 +08:00
|
|
|
|
byte[] IV = { 0x01,0x02,0x03,0x14,0x05,0x06,0x17,0x08 };
|
|
|
|
|
string key = "12365478";
|
|
|
|
|
var des = DesHelper.GetHelper(PaddingMode.PKCS7,CipherMode.CBC,IV);
|
|
|
|
|
Console.WriteLine($"Key:{key}");
|
2019-03-07 16:10:37 +08:00
|
|
|
|
string mingwen = getMingWen();
|
|
|
|
|
Console.WriteLine($"明文:{mingwen}");
|
2019-03-14 14:12:09 +08:00
|
|
|
|
var miwen = des.Encrypty(key,mingwen);
|
2019-03-07 16:10:37 +08:00
|
|
|
|
Console.WriteLine($"密文:{miwen}");
|
2019-03-14 14:12:09 +08:00
|
|
|
|
var miwen2 = des.Encrypty(key,mingwen);
|
|
|
|
|
Console.WriteLine($"密文2:{miwen2}");
|
|
|
|
|
Assert.AreEqual(miwen,miwen2);
|
|
|
|
|
var mingwen2 = des.DesCrypty(key,miwen);
|
2019-03-07 16:10:37 +08:00
|
|
|
|
Assert.AreEqual(mingwen,mingwen2);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string getMingWen() {
|
2019-03-14 14:12:09 +08:00
|
|
|
|
string str = "abcdefghijklmnopqrstuvwxyz1234567890,./*-+";
|
2019-03-07 16:10:37 +08:00
|
|
|
|
var result = new StringBuilder();
|
2019-03-14 14:12:09 +08:00
|
|
|
|
int len = 100;
|
2019-03-07 16:10:37 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|