wsd_djy/WebSiteCode/Cmdjy/CmdjyTests/Bll/DesHelperTests.cs

40 lines
1.4 KiB
C#
Raw Normal View History

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 = "12365478";
var des = DesHelper.GetHelper(PaddingMode.PKCS7,CipherMode.CBC,IV);
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();
}
}
}