增加项目,分层
This commit is contained in:
1 parent
6e995a5bdb
commit
0a3e5af6a9
234 files changed
+26994
-1
No files matched your search
@@ -0,0 +1,144 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Client.Helpers
|
||||
{
|
||||
public class DataOpenSSL
|
||||
{
|
||||
public static byte[] key = new byte[32] { 145, 232, 156, 201, 201, 0, 42, 184, 222, 111, 109, 49, 226, 169, 9, 44, 151, 148, 143, 120, 62, 84, 30, 170, 127, 242, 20, 141, 231, 33, 230, 6 };
|
||||
public static byte[] iv = new byte[16] { 113, 6, 75, 177, 160, 112, 73, 39, 178, 147, 82, 107, 186, 58, 144, 187 };
|
||||
|
||||
public static string EncryptString(string plainText)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
// Instantiate a new Aes object to perform string symmetric encryption
|
||||
Aes encryptor = Aes.Create();
|
||||
|
||||
encryptor.Mode = CipherMode.CBC;
|
||||
|
||||
// Set key and IV
|
||||
byte[] aesKey = new byte[32];
|
||||
Array.Copy(key, 0, aesKey, 0, 32);
|
||||
encryptor.Key = aesKey;
|
||||
encryptor.IV = iv;
|
||||
|
||||
// Instantiate a new MemoryStream object to contain the encrypted bytes
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
|
||||
// Instantiate a new encryptor from our Aes object
|
||||
ICryptoTransform aesEncryptor = encryptor.CreateEncryptor();
|
||||
|
||||
// Instantiate a new CryptoStream object to process the data and write it to the
|
||||
// memory stream
|
||||
CryptoStream cryptoStream = new CryptoStream(memoryStream, aesEncryptor, CryptoStreamMode.Write);
|
||||
|
||||
// Convert the plainText string into a byte array
|
||||
byte[] plainBytes = Encoding.UTF8.GetBytes(plainText);
|
||||
|
||||
// Encrypt the input plaintext string
|
||||
cryptoStream.Write(plainBytes, 0, plainBytes.Length);
|
||||
|
||||
// Complete the encryption process
|
||||
cryptoStream.FlushFinalBlock();
|
||||
|
||||
// Convert the encrypted data from a MemoryStream to a byte array
|
||||
byte[] cipherBytes = memoryStream.ToArray();
|
||||
|
||||
// Close both the MemoryStream and the CryptoStream
|
||||
memoryStream.Close();
|
||||
cryptoStream.Close();
|
||||
|
||||
// Convert the encrypted byte array to a base64 encoded string
|
||||
string cipherText = Convert.ToBase64String(cipherBytes, 0, cipherBytes.Length);
|
||||
|
||||
|
||||
cipherText = cipherText.Replace("+", "-").Replace("/", "_").Replace("=", "");
|
||||
|
||||
// Return the encrypted data as a string
|
||||
return cipherText;
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
//throw;
|
||||
}
|
||||
return plainText;
|
||||
}
|
||||
|
||||
public static string DecryptString(string cipherText)
|
||||
{
|
||||
cipherText = cipherText.Replace("-", "+").Replace("_", "/");
|
||||
var x1 = cipherText.Length % 4;
|
||||
if (x1 > 0)
|
||||
{
|
||||
cipherText = cipherText + "====".Substring(x1);
|
||||
}
|
||||
// Instantiate a new Aes object to perform string symmetric encryption
|
||||
Aes encryptor = Aes.Create();
|
||||
|
||||
encryptor.Mode = CipherMode.CBC;
|
||||
|
||||
// Set key and IV
|
||||
byte[] aesKey = new byte[32];
|
||||
Array.Copy(key, 0, aesKey, 0, 32);
|
||||
encryptor.Key = aesKey;
|
||||
encryptor.IV = iv;
|
||||
|
||||
// Instantiate a new MemoryStream object to contain the encrypted bytes
|
||||
MemoryStream memoryStream = new MemoryStream();
|
||||
|
||||
// Instantiate a new encryptor from our Aes object
|
||||
ICryptoTransform aesDecryptor = encryptor.CreateDecryptor();
|
||||
|
||||
// Instantiate a new CryptoStream object to process the data and write it to the
|
||||
// memory stream
|
||||
CryptoStream cryptoStream = new CryptoStream(memoryStream, aesDecryptor, CryptoStreamMode.Write);
|
||||
|
||||
// Will contain decrypted plaintext
|
||||
string plainText = String.Empty;
|
||||
|
||||
try
|
||||
{
|
||||
// Convert the ciphertext string into a byte array
|
||||
byte[] cipherBytes = Convert.FromBase64String(cipherText);
|
||||
|
||||
// Decrypt the input ciphertext string
|
||||
cryptoStream.Write(cipherBytes, 0, cipherBytes.Length);
|
||||
|
||||
// Complete the decryption process
|
||||
cryptoStream.FlushFinalBlock();
|
||||
|
||||
// Convert the decrypted data from a MemoryStream to a byte array
|
||||
byte[] plainBytes = memoryStream.ToArray();
|
||||
|
||||
// Convert the decrypted byte array to string
|
||||
plainText = Encoding.UTF8.GetString(plainBytes, 0, plainBytes.Length);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
//throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Close both the MemoryStream and the CryptoStream
|
||||
memoryStream.Close();
|
||||
cryptoStream.Close();
|
||||
}
|
||||
|
||||
// Return the decrypted data as a string
|
||||
return plainText;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
using Store.Framework.Configs;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Store.Framework.Helpers
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件操作帮助类
|
||||
/// </summary>
|
||||
public class FileHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取文件MD5值
|
||||
/// </summary>
|
||||
/// <param name="FilePath"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetFileMd5(string FilePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
FileStream get_file = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
|
||||
System.Security.Cryptography.MD5CryptoServiceProvider get_md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
|
||||
byte[] hash_byte = get_md5.ComputeHash(get_file);
|
||||
string resule = BitConverter.ToString(hash_byte);
|
||||
resule = resule.Replace("-", "");
|
||||
get_file.Close();
|
||||
return resule;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return e.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 读取所有内容 相对路径Or绝对路径
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static string ReadAllText(string file)
|
||||
{
|
||||
if (!Path.IsPathRooted(file))
|
||||
{
|
||||
file = Path.Combine(GlobalConfig.AppDirectory, file);
|
||||
}
|
||||
if (File.Exists(file))
|
||||
{
|
||||
return _ReadAllText(file, Encoding.UTF8);
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取所有内容 绝对路径
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static string ReadAbsAllText(string file)
|
||||
{
|
||||
return _ReadAllText(file, Encoding.UTF8);
|
||||
}
|
||||
/// <summary>
|
||||
/// 读取所有内容 相对路径
|
||||
/// </summary>
|
||||
/// <param name="file"></param>
|
||||
/// <returns></returns>
|
||||
public static string ReadPartialAllText(string file)
|
||||
{
|
||||
string _file = Path.Combine(GlobalConfig.AppDirectory, file);
|
||||
return _ReadAllText(_file, Encoding.UTF8);
|
||||
}
|
||||
|
||||
private static string _ReadAllText(string file, Encoding encoding)
|
||||
{
|
||||
if (File.Exists(file))
|
||||
{
|
||||
return File.ReadAllText(file, encoding);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"缺失文件{file}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user