Repository navigation
Expand file tree
/
Copy pathCore.cs
More file actions
132 lines (118 loc) · 3.68 KB
/
Copy pathCore.cs
File metadata and controls
132 lines (118 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Text;
using WSharp.Generic;
using WSharp.Core;
using WSharp.Data;
using System.Web;
using System.Security.Cryptography;
namespace UnitTest
{
[TestClass]
public class Core
{
public const string str = "123456";
public Core()
{
//
//TODO: 在此处添加构造函数逻辑
//
}
private TestContext testContextInstance;
/// <summary>
///获取或设置测试上下文,该上下文提供
///有关当前测试运行及其功能的信息。
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
#region 附加测试特性
//
// 编写测试时,可以使用以下附加特性:
//
// 在运行类中的第一个测试之前使用 ClassInitialize 运行代码
[ClassInitialize()]
public static void MyClassInitialize(TestContext testContext)
{
testContext.AddResultFile("TestResult.txt");
}
//
// 在类中的所有测试都已运行之后使用 ClassCleanup 运行代码
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// 在运行每个测试之前,使用 TestInitialize 来运行代码
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// 在每个测试运行完之后,使用 TestCleanup 来运行代码
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
[TestMethod]
public void Replace()
{
string str = "01234567";
Assist.Replace(str, 'A', 0, 2, 4, 6, 8, 10);
// result:
// str = "A1A3A5A7"
}
[TestMethod]
public void TryToInt()
{
string s = "0x890"; //
int try_to_int = s.TryToInt() ?? int.MinValue;
// int convert_int = Convert.ToInt32(s);
// 两个都转换失败,TryToInt 不抛异常,只返回null
}
[TestMethod]
public void Aes()
{
string original = "Here is some data to encrypt";
using (AesCryptoServiceProvider aes = new AesCryptoServiceProvider())
{
byte[] encrypted = Security.AesEncrypt(original, aes.Key, aes.IV);
string roundtrip = Security.AesDecrypt(encrypted, aes.Key, aes.IV);
}
}
[TestMethod]
public void Des()
{
string original = "Here is some data to encrypt";
using (TripleDESCryptoServiceProvider des = new TripleDESCryptoServiceProvider())
{
byte[] encrypted = Security.DesEncrypt(original, des.Key, des.IV);
string roundtrip = Security.DesDecrypt(encrypted, des.Key, des.IV);
}
}
[TestMethod]
public void SHA1()
{
var result = Security.SHA1Encrypt(str);
}
[TestMethod]
public void RSA()
{
string public_key, private_key;
Security.RSAKey(out private_key, out public_key);
var bytes = Security.RSAEncrypt(public_key, str);
var result = Security.RSADecrypt(private_key, bytes);
}
[TestMethod]
public void MongoID()
{
Console.WriteLine(Assist.MongoID);
}
}
}