de2bd2f9
“wangming”
项目初始化
|
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.IO;
using System.Web;
namespace NCC.Code
{
public static class StringExtension
{
#region 字符串判断
/// <summary>
/// 是否为用户上行短信验证码
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool M5_IsSMSReplyCode(this string str)
{
str = str.Trim();
if (str.Length != 6)
{
return false;
}
int tmp = 0;
int.TryParse(str, out tmp);
if (tmp <= 0)
{
return false;
}
return true;
}
/// <summary>
/// 判断是否是手机号
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static bool M5_IsMobile(this string str)
{
return new Regex("^1[3,4,5,7,8,9]\\d{9}$").IsMatch(str);
}
#endregion
#region 字符串处理
public static string StrCharcoder(this string str)
{
return str.Replace("\\", "").Replace("\"", "").Trim();
}
public static string M5_RemoveEnter(this string str)
{
return str.Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
}
#region 字符串转码
/// <summary>
/// Base64加密
/// </summary>
/// <param name="codeName">加密采用的编码方式</param>
/// <param name="source">待加密的明文</param>
/// <returns></returns>
public static string M5_EncodeBase64(this string source, Encoding encode)
{
string enstring = "";
byte[] bytes = encode.GetBytes(source);
try
{
enstring = Convert.ToBase64String(bytes);
}
catch
{
enstring = source;
}
return enstring;
}
/// <summary>
/// 中文转unicode
/// </summary>
/// <returns></returns>
public static string StrDecode(this string str)
{
string outStr = "";
if (!string.IsNullOrEmpty(str))
{
for (int i = 0; i < str.Length; i++)
{
outStr += "/u" + ((int)str[i]).ToString("x");
}
}
return outStr;
}
/// <summary>
/// unicode转中文
/// </summary>
/// <returns></returns>
public static string StrEncode(this string str)
{
string outStr = "";
if (!string.IsNullOrEmpty(str))
{
string[] strlist = str.Replace("/", "").Split('u');
try
{
for (int i = 1; i < strlist.Length; i++)
{
//将unicode字符转为10进制整数,然后转为char中文字符
outStr += (char)int.Parse(strlist[i], System.Globalization.NumberStyles.HexNumber);
}
}
catch (FormatException ex)
{
outStr = ex.Message;
}
}
return outStr;
}
/// <summary>
/// unicode转中文(符合js规则的)
/// </summary>
/// <returns></returns>
public static string StrJsDecode(this string str)
{
string outStr = "";
Regex reg = new Regex(@"(?i)\\u([0-9a-f]{4})");
outStr = reg.Replace(str, delegate (Match m1)
{
return ((char)Convert.ToInt32(m1.Groups[1].Value, 16)).ToString();
});
return outStr;
}
/// <summary>
/// 中文转unicode(符合js规则的)
/// </summary>
/// <returns></returns>
public static string StrJsEncode(this string str)
{
string outStr = "";
if (!string.IsNullOrEmpty(str))
{
for (int i = 0; i < str.Length; i++)
{
if (Regex.IsMatch(str[i].ToString(), @"[\u4e00-\u9fa5]")) { outStr += "\\u" + ((int)str[i]).ToString("x"); }
else { outStr += str[i]; }
}
}
return outStr;
}
/// <summary>
/// url字符串编码
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string M5_UrlEncode(this string str)
{
Encoding utf8 = Encoding.UTF8;
return HttpUtility.UrlEncode(str, utf8);
}
/// <summary>
/// url字符串解码
/// </summary>
/// <param name="str"></param>
/// <returns></returns>
public static string M5_UrlDecode(this string str)
{
Encoding utf8 = Encoding.UTF8;
return HttpUtility.UrlDecode(str, utf8);
}
#endregion
#region 字符串截取
/// <summary>
/// 返回截取固定长度字符串
/// </summary>
/// <param name="queryString"></param>
/// <param name="num"></param>
/// <returns></returns>
public static string SubString(this string queryString, int num)
{
if (queryString == null)
return string.Empty;
num = num > queryString.Length ? queryString.Length : num;
return queryString.Substring(0, num);
}
/// <summary>
/// 返回截取固定长度字符串
/// </summary>
/// <param name="queryString"></param>
/// <param name="num"></param>
/// <returns></returns>
public static string SubString(this string queryString, int num, string defaultstr)
{
if (queryString == null)
return string.Empty;
num = num > queryString.Length ? queryString.Length : num;
return queryString.Substring(0, num) + defaultstr;
}
/// <summary>
/// md532加密码处理
/// 规则:截前2位和后3位
/// </summary>
/// <param name="queryString">加密字符串</param>
/// <returns></returns>
public static string Md532SubString(this string queryString)
{
if (queryString == null)
return string.Empty;
int len = queryString.Length;
if (len != 32)
return queryString;
queryString = queryString.Substring(2, 27);
return queryString;
}
#endregion
#region 字符串过滤
/// <summary>
/// 返回过滤不安全字符<> htmlecode
/// </summary>
/// <param name="queryString">字符串</param>
/// <returns></returns>
public static string StrFilter(this string queryString)
{
if (queryString == null)
return string.Empty;
return queryString.Replace("<", "<")
.Replace(">", ">");
}
/// <summary>
/// 返回过滤不安全字符<>转全角
/// </summary>
/// <param name="queryString">字符串</param>
/// <returns></returns>
public static string StrFilterFull(this string queryString)
{
if (queryString == null)
return string.Empty;
return queryString.Replace("<", "<")
.Replace(">", ">");
}
/// <summary>
/// 返回过滤不安全字符去除<>包含里面的内容
/// </summary>
/// <param name="queryString">过滤的内容</param>
/// <returns></returns>
public static string StrFilter(this string queryString, bool replace)
{
if (queryString == null)
return string.Empty;
return Regex.Replace(queryString, "<.*?>", "");
}
/// <summary>
/// lucene保留关键字过滤
/// </summary>
/// <param name="queryString">过滤关键字</param>
/// <returns></returns>
public static string LuceneStrStaticFilter(this string queryString)
{
if (queryString == null)
return string.Empty;
return queryString.Replace("+", "")
.Replace("-", "")
.Replace("&", "")
.Replace("|", "")
.Replace("!", "")
.Replace("(", "")
.Replace(")", "")
.Replace("{", "")
.Replace("}", "")
.Replace("[", "")
.Replace("]", "")
.Replace("^", "")
.Replace("~", "")
.Replace("*", "")
.Replace("?", "")
.Replace("'", "")
.Replace(":", "")
.Replace("\\", "")
.Replace("\"", "")
.Replace("AND", "")
.Replace("OR", "")
.Replace("NOT", "");
}
/// <summary>
/// SQL防注入
/// </summary>
/// <param name="InText">要过滤的字符串 </param>
/// <returns>如果参数存在不安全字符,则返回true</returns>
public static bool IsSqlTextSafe(this string queryString)
{
if (queryString == null)
{
return false;
}
string word = @"and|exec|select|update|delete|drop|chr|mid|master|truncate|char|declare|join|cmd";//这里加要过滤的SQL字符
if (Regex.IsMatch(queryString.ToLower(), word.ToLower(), RegexOptions.IgnoreCase))
return true;
return false;
}
/// <summary>
/// SQl防止注入
/// </summary>
/// <param name="queryString"></param>
/// <returns></returns>
public static bool IsSqlTextSafe(this string queryString, bool old)
{
if (queryString == null)
{
return false;
}
//过滤关键字
string StrKeyWord = @"exec|select|insert|delete|from|count\(|drop table|update|truncate|asc\(|mid\(|char\(|xp_cmdshell|exec master|netlocalgroup administrators|net user|""|or|and";
//过滤关键字符
string StrRegex = @"[;|%|\@|*|!|']";
if (Regex.IsMatch(queryString.ToLower(), StrKeyWord.ToLower(), RegexOptions.IgnoreCase) ||
Regex.IsMatch(queryString.ToLower(), StrRegex.ToLower()))
return true;
return false;
}
/// <summary>
/// SQL防注入
/// </summary>
/// <param name="InText">要过滤的字符串 </param>
/// <returns>如果参数存在不安全字符,则返回true</returns>
public static string SqlTextFilter(this string queryString)
{
if (queryString == null)
return string.Empty;
return queryString//.Replace("and", "")
.Replace("exec", "")
//.Replace("select", "")
.Replace("chr", "")
.Replace("mid", "")
.Replace("master", "")
.Replace("or", "")
.Replace("truncate", "")
.Replace("char", "")
.Replace("declare", "")
.Replace("join", "")
.Replace("cmd", "")
.Replace(";", "")
.Replace("'", "")
.Replace("update", "")
.Replace("insert", "")
.Replace("drop", "")
.Replace("delete", "");
}
public static string ArryJoinString(this List<int> arry, string split = ",")
{
if (arry == null || arry.Count < 1)
return string.Empty;
return String.Join(split, arry);
}
public static string ArryJoinString(this List<string> arry, string split = ",")
{
if (arry == null || arry.Count < 1)
return string.Empty;
return String.Join(split, arry);
}
public static string ArryJoinStringForSql(this List<string> arry, string split = ",")
{
if (arry == null || arry.Count < 1)
return string.Empty;
List<string> tmp = new List<string>();
foreach (var item in arry)
{
tmp.Add($"'{item}'");
}
return String.Join(split, tmp);
}
//public static string SqlCharIndexFilter(this List<int> arry, string field, string other = "")
//{
// string where = string.Empty;
// List<string> list = new List<string>();
// foreach (int item in arry)
// {
// list.Add($" CHARINDEX(',{item},',','+{field}+',') > 0 ");
// }
// if (other.IsNotNullOrEmpty())
// {
// list.Add(other);
// }
// where = $" and ( {list.ArryJoinString(" or ")}) ";
// return where;
//}
//public static string SqlCharIndexFilter(this List<string> arry, string field)
//{
// string where = string.Empty;
// List<string> list = new List<string>();
// foreach (string item in arry)
// {
// list.Add($" CHARINDEX(','{item}',',','+{field}+',') > 0 ");
// }
// where = $" and ( {list.ArryJoinString(" or ")}) ";
// return where;
//}
#endregion
#region 字符串转换
public static string[] M5_Split(this string str, string split_str)
{
try
{
return str.Split(new[] { split_str }, StringSplitOptions.None);
}
catch (Exception ex)
{
return new string[] { };
}
}
public static List<string> M5_SplitToList(this string str, string split_str)
{
try
{
return str.Split(new[] { split_str }, StringSplitOptions.None).ToList();
}
catch (Exception ex)
{
return new List<string>();
}
}
public static List<int> M5_SplitToIntList(this string str, string split_str)
{
try
{
return M5_SplitToList(str, split_str).Select(o => o.ObjToInt()).ToList();
}
catch (Exception ex)
{
return new List<int>();
}
}
/// <summary>
///返回 List<int>数组转换成string字符串 中间 ',' 号隔开
/// </summary>
/// <param name="list">数组</param>
/// <returns></returns>
public static string ListToString(this List<int> list)
{
if (list == null || list.Count == 0)
return string.Empty;
StringBuilder retStr = new StringBuilder();
foreach (int item in list)
{
retStr.AppendFormat(",{0}", item.ToString());
}
return retStr.Remove(0, 1).ToString();
}
/// <summary>
///返回 List<int>数组转换成string字符串 中间 ',' 号隔开
/// </summary>
/// <param name="list">数组</param>
/// <returns></returns>
public static string ListToString(this List<string> list)
{
if (list == null || list.Count == 0)
return string.Empty;
StringBuilder retStr = new StringBuilder();
foreach (string item in list)
{
retStr.AppendFormat(",'{0}'", item.ToString());
}
return retStr.Remove(0, 1).ToString();
}
/// <summary>
///返回 List<int>数组转换成string字符串 中间 ',' 号隔开
/// </summary>
/// <param name="list">数组</param>
/// <returns></returns>
public static string ListToStrings(this List<string> list)
{
if (list == null || list.Count == 0)
return string.Empty;
StringBuilder retStr = new StringBuilder();
foreach (string item in list)
{
retStr.AppendFormat(",{0}", item.ToString());
}
return retStr.Remove(0, 1).ToString();
}
/// <summary>
///返回 List<int>数组转换成string字符串 按照指定分隔符转化
/// </summary>
/// <param name="list">数组</param>
/// <param name="split">分隔符</param>
/// <returns></returns>
public static string ListToString(this List<int> list, byte split)
{
if (list == null || split == null || list.Count == 0)
return string.Empty;
StringBuilder retStr = new StringBuilder();
foreach (int item in list)
{
retStr.AppendFormat("{0}{1}", split, item.ToString());
}
return retStr.Remove(0, 1).ToString();
}
/// <summary>
/// 时间撮转换成 datetime时间
/// </summary>
/// <param name="timeStamp">时间戳</param>
/// <returns></returns>
public static DateTime TimeStampConvertDateTime(this string timeStamp)
{
DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
return dateTimeStart.Add(toNow);
}
/// <summary>
/// 时间转换成时间撮
/// </summary>
/// <param name="time">时间</param>
/// <returns></returns>
public static string DateTimeConvertTimeStamp(this DateTime time)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return (time - startTime).TotalSeconds.ToString().Substring(0, 10);
}
/// <summary>
/// 日期转换成unix时间戳
/// </summary>
/// <param name="dateTime"></param>
/// <returns></returns>
public static string DateTimeToUnixTimestamp(this DateTime dateTime)
{
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return ((int)(dateTime - startTime).TotalSeconds).ToString();
}
/// <summary>
/// unix时间戳转换成日期
/// </summary>
/// <param name="unixTimeStamp">时间戳(秒)</param>
/// <returns></returns>
public static DateTime UnixTimestampToDateTime(this string timeStamp)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
return dtStart.Add(toNow);
}
#endregion
#region 字符串加(解)密
/// <summary>
/// SHA1加密
/// </summary>
public static string SHA1Encrypt(this string encryptString)
{
byte[] StrRes = Encoding.Default.GetBytes(encryptString);
HashAlgorithm iSHA = new SHA1CryptoServiceProvider();
StrRes = iSHA.ComputeHash(StrRes);
StringBuilder EnText = new StringBuilder();
foreach (byte iByte in StrRes)
{
EnText.AppendFormat("{0:x2}", iByte);
}
return EnText.ToString();
}
public static string SHA1EncryptRoWx(this string encryptString)
{
byte[] cleanBytes = Encoding.Default.GetBytes(encryptString);
byte[] hashedBytes = System.Security.Cryptography.SHA1.Create().ComputeHash(cleanBytes);
return BitConverter.ToString(hashedBytes).Replace("-", "").ToLower();
}
/// <summary>
/// 返回MD5加密后的字符串
/// </summary>
/// <param name="str">原始字符串</param>
/// <returns>MD5加密字符串</returns>
public static string StringToMd5(this string encryptString)
{
byte[] b = Encoding.Default.GetBytes(encryptString);
b = new MD5CryptoServiceProvider().ComputeHash(b);
string ret = "";
for (int i = 0; i < b.Length; i++)
ret += b[i].ToString("x").PadLeft(2, '0');
return ret;
}
public static string StringToMd5(this string encryptString, Encoding ecode)
{
byte[] b = ecode.GetBytes(encryptString);
b = new MD5CryptoServiceProvider().ComputeHash(b);
string ret = "";
for (int i = 0; i < b.Length; i++)
ret += b[i].ToString("x").PadLeft(2, '0');
return ret;
}
/// <summary>
/// RSA加密
/// </summary>
/// <param name="publickey"></param>
/// <param name="content"></param>
/// <returns></returns>
public static string RSAEncrypt(this string content, string publickey)
{
if (content.IsNull() || publickey.IsNull())
{
return string.Empty;
}
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAKeyInfo = new RSAParameters();
byte[] bytearr = Convert.FromBase64String(publickey);
RSAKeyInfo.Modulus = bytearr.ToList().GetRange(29, bytearr.Length - 34).ToArray();
RSAKeyInfo.Exponent = Convert.FromBase64String("AQAB");
RSA.ImportParameters(RSAKeyInfo);
byte[] bytes = RSA.Encrypt(UTF8Encoding.UTF8.GetBytes(content), false);
return Convert.ToBase64String(bytes);
}
///// <summary>
///// RSA加密
///// </summary>
///// <param name="xmlPublicKey">公钥</param>
///// <param name="m_strEncryptString">MD5加密后的数据</param>
///// <returns>RSA公钥加密后的数据</returns>
//public static string XFRSAEncrypt(this string content, string publickey)
//{
// if (content.IsNull() || publickey.IsNull())
// {
// return string.Empty;
// }
// //publickey = "<RSAKeyValue><Modulus>w5x7MPzqx+zYboYDp3RCVOUu0DlvN4qXCmjfI5LX6nw4E4shN8DWxC/Tk9h4CaB+ycIEN+6qiZpEf9g50nhS9LI2sEDQwYsRfGCsnkOvBUwF2efaNZhtelWSRZpqiyvt9c0By53qXuHtNrpZEh+pFc4Eh34eFv2HucBXxyHchpM=</Modulus><Exponent>AQAB</Exponent></RSAKeyValue>";
// RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
// byte[] cipherbytes;
// rsa.FromXmlString(publickey);
// cipherbytes = rsa.Encrypt(Encoding.UTF8.GetBytes(content), false);
// return Convert.ToBase64String(cipherbytes);
//}
public static string XFRSAEncrypt(this string content, string publickey)
{
if (content.IsNull() || publickey.IsNull())
{
return string.Empty;
}
//publickey = "w5x7MPzqx+zYboYDp3RCVOUu0DlvN4qXCmjfI5LX6nw4E4shN8DWxC/Tk9h4CaB+ycIEN+6qiZpEf9g50nhS9LI2sEDQwYsRfGCsnkOvBUwF2efaNZhtelWSRZpqiyvt9c0By53qXuHtNrpZEh+pFc4Eh34eFv2HucBXxyHchpM=";
RSACryptoServiceProvider RSA = new RSACryptoServiceProvider();
RSAParameters RSAKeyInfo = new RSAParameters();
RSAKeyInfo.Modulus = Convert.FromBase64String(publickey);
RSAKeyInfo.Exponent = Convert.FromBase64String("AQAB");
RSA.ImportParameters(RSAKeyInfo);
byte[] bytes = RSA.Encrypt(UTF8Encoding.UTF8.GetBytes(content), false);
return Convert.ToBase64String(bytes);
}
/// <summary>
/// RSA解密
/// </summary>
/// <param name="xmlPrivateKey">私钥</param>
/// <param name="m_strDecryptString">待解密的数据</param>
/// <returns>解密后的结果</returns>
public static string XFRSADecrypt(this string content, string privatekey)
{
if (content.IsNull() || privatekey.IsNull())
{
return string.Empty;
}
//privatekey = "<RSAKeyValue><Modulus>w5x7MPzqx+zYboYDp3RCVOUu0DlvN4qXCmjfI5LX6nw4E4shN8DWxC/Tk9h4CaB+ycIEN+6qiZpEf9g50nhS9LI2sEDQwYsRfGCsnkOvBUwF2efaNZhtelWSRZpqiyvt9c0By53qXuHtNrpZEh+pFc4Eh34eFv2HucBXxyHchpM=</Modulus><Exponent>AQAB</Exponent><P>yRXQLm3u9b0WyzJeMzS7kvdWDlMxFh0gjtH8hPyFWkXi/eI1ek7YLL2lgopimq4zfVK3jWHF4h5aH+ayXdP0yw==</P><Q>+Qf5qTfNDsR6xd028uVsE9RKyFqhiyfgs7DT3XDgIXgZ0N21ztplup7pp9+6IHaC1qJ8NxaVzeFZ7fBmzCPEWQ==</Q><DP>HRl3AwENr6opfkZPs4FSE7aPUYtgcx7L818X9/bDJYkvjCYMLyLxzae0J+v20QOcl+o8fc1EYbCawjsUXNereQ==</DP><DQ>mSc3esNvoCJj4yYeMhm4cyV/bGKYsQ0wWzJnyesuXEcRkWuY8YNNRw2OY4jrXiWkZ738KKECNmDePsA3aFqi2Q==</DQ><InverseQ>QdAD7Nmv3llzZaipbECCLWiyQyuJfVmOFvoPgJiIeEVZnXr86fsyXB8jyn2cctvdSqeAu1OXOYBsL1vkQ29efQ==</InverseQ><D>Sbnn4J3i67mEFZwjMnEqMw8yZr7PAVMV/JFsUN8ezD1HcW5F9dqT19vi1d2H2LEKOIcMyfwFgNmJKdpYaNB7Cx+dcvJ+iZWfFrRrjqz8l9GXsTycyyw2r/OUJu0UV6khW6qRL7kiFYj7Dny8ZvccwVOjBT56ja76LpOJ1ogRT7E=</D></RSAKeyValue>";
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider();
byte[] cipherbytes;
rsa.FromXmlString(privatekey);
try
{
cipherbytes = rsa.Decrypt(Convert.FromBase64String(content), false);
}
catch (Exception)
{
return string.Empty;
}
return Encoding.UTF8.GetString(cipherbytes);
}
#endregion
#region 字符串格式化
public static string StrToString(this object str)
{
return str == null ? string.Empty : str.ToString();
}
/// <summary>
/// datetime转换
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public static string TimeToString(this DateTime time)
{
return time == null ? string.Empty : time.ToString("yyyy-MM-dd HH:mm:ss");
}
#endregion
public static string ArryJoinStringDoubleSql(this List<string> arry, string split = ",")
{
if (arry == null || arry.Count < 1)
return string.Empty;
List<string> tmp = new List<string>();
foreach (var item in arry)
{
tmp.Add($"\"{item}\"");
}
return String.Join(split, tmp);
}
public static List<string> StringToArry(this string arry, char split = ',')
{
List<string> list = new List<string>();
try
{
list = arry.Split(split).ToList();
}
catch (Exception)
{
}
return list;
}
#endregion
}
}
|